package day10

import java.io.File
import java.util.ArrayDeque

val INPUT = "input.txt"

fun old() {
    val scoreMap = mapOf(')' to 3, ']' to 57, '}' to 1197, '>' to 25137)
    val chars: CharSequence = "([{<)]}>"
    val charMap = mapOf('(' to 0, ')' to 4,
                        '[' to 1, ']' to 5,
                        '{' to 2, '}' to 6,
                        '<' to 3, '>' to 7)
    var syntaxScore = 0
    var complScores = ArrayList<Long>()
    var stack = ArrayDeque<Int>()
    File(INPUT).forEachLine {
        stack.clear()
        var complScore: Long = 0
        var discard = false
        for (char in it) {
            var value = charMap.getValue(char)
            when (value) {
                in 0..3 -> {
                    stack.push(value)
                    print(char)
                }
                in 4..7 -> {
                    var eval = stack.pop()
                    if (eval - (value - 4) != 0) {
                        syntaxScore += scoreMap.getValue(char)
                        discard = true
                        print("\u001b[31m" + char + "\u001b[0m")
                        break;
                    }
                    else {
                        print(char)
                    }
                }
            }
        }

        if (!discard) {
            val len = stack.size
            for (i in 0..(len - 1)) {
                val value = (stack.pop() + 4)
                val char = chars[value]
                complScore = (complScore * 5) + (value - 3).toLong()
                print("\u001b[32m" + char + "\u001b[0m")
            }
            complScores.add(complScore)
        }
        print('\n')
    }
    complScores.sort()
    println("Syntax score: ${syntaxScore}")
    println("Mid score: ${complScores[(complScores.size / 2.0).toInt()]}")
}

fun new() {
    val scoreMap = mapOf(')' to 3, ']' to 57, '}' to 1197, '>' to 25137)
    val pairs = mapOf('(' to ')', '[' to ']', '{' to '}', '<' to '>')
    val pairKeys = pairs.keys
    var syntaxScore = 0
    var complScores = mutableListOf<Long>()
    var stack = mutableListOf<Char>()
    File(INPUT).forEachLine { line ->
        stack.clear()
        for (char in line) {
            if (char in pairKeys) { stack.add(char) }
            else if (char == pairs[stack.lastOrNull()]) { stack.removeLast() }
            else { syntaxScore += scoreMap[char]!!; stack.clear(); break }
        }
        if (stack.size > 0) complScores.add(stack.reversed().map { pairKeys.indexOf(it) + 1 }.fold(0L) { acc, x -> acc * 5 + x})
    }
    println("Syntax score: ${syntaxScore}, Mid score: ${complScores.sorted()[(complScores.size / 2.0).toInt()]}")
}

fun main() {
    old()
    println("===================================")
    new()
}

Compiled from "App.kt"
public final class day10.AppKt {
  private static final java.lang.String INPUT;

  public static final java.lang.String getINPUT();
    Code:
       0: getstatic     #11                 // Field INPUT:Ljava/lang/String;
       3: areturn

  public static final void old();
    Code:
       0: iconst_4
       1: anewarray     #15                 // class kotlin/Pair
       4: astore_1
       5: aload_1
       6: iconst_0
       7: bipush        41
       9: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      12: iconst_3
      13: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      16: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      19: aastore
      20: aload_1
      21: iconst_1
      22: bipush        93
      24: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      27: bipush        57
      29: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      35: aastore
      36: aload_1
      37: iconst_2
      38: bipush        125
      40: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      43: sipush        1197
      46: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      52: aastore
      53: aload_1
      54: iconst_3
      55: bipush        62
      57: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      60: sipush        25137
      63: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      69: aastore
      70: aload_1
      71: invokestatic  #38                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      74: astore_0
      75: ldc           #40                 // String ([{<)]}>
      77: checkcast     #42                 // class java/lang/CharSequence
      80: astore_1
      81: bipush        8
      83: anewarray     #15                 // class kotlin/Pair
      86: astore_3
      87: aload_3
      88: iconst_0
      89: bipush        40
      91: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      94: iconst_0
      95: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      98: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     101: aastore
     102: aload_3
     103: iconst_1
     104: bipush        41
     106: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     109: iconst_4
     110: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     113: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     116: aastore
     117: aload_3
     118: iconst_2
     119: bipush        91
     121: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     124: iconst_1
     125: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     128: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     131: aastore
     132: aload_3
     133: iconst_3
     134: bipush        93
     136: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     139: iconst_5
     140: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     146: aastore
     147: aload_3
     148: iconst_4
     149: bipush        123
     151: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     154: iconst_2
     155: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     158: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     161: aastore
     162: aload_3
     163: iconst_5
     164: bipush        125
     166: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     169: bipush        6
     171: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     174: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     177: aastore
     178: aload_3
     179: bipush        6
     181: bipush        60
     183: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     186: iconst_3
     187: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     190: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     193: aastore
     194: aload_3
     195: bipush        7
     197: bipush        62
     199: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     202: bipush        7
     204: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     207: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     210: aastore
     211: aload_3
     212: invokestatic  #38                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     215: astore_2
     216: new           #44                 // class kotlin/jvm/internal/Ref$IntRef
     219: dup
     220: invokespecial #47                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     223: astore_3
     224: new           #49                 // class kotlin/jvm/internal/Ref$ObjectRef
     227: dup
     228: invokespecial #50                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
     231: astore        4
     233: aload         4
     235: new           #52                 // class java/util/ArrayList
     238: dup
     239: invokespecial #53                 // Method java/util/ArrayList."<init>":()V
     242: putfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     245: new           #49                 // class kotlin/jvm/internal/Ref$ObjectRef
     248: dup
     249: invokespecial #50                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
     252: astore        5
     254: aload         5
     256: new           #59                 // class java/util/ArrayDeque
     259: dup
     260: invokespecial #60                 // Method java/util/ArrayDeque."<init>":()V
     263: putfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     266: new           #62                 // class java/io/File
     269: dup
     270: getstatic     #11                 // Field INPUT:Ljava/lang/String;
     273: invokespecial #65                 // Method java/io/File."<init>":(Ljava/lang/String;)V
     276: aconst_null
     277: aload         5
     279: aload_2
     280: aload_3
     281: aload_0
     282: aload_1
     283: aload         4
     285: invokedynamic #85,  0             // InvokeDynamic #0:invoke:(Lkotlin/jvm/internal/Ref$ObjectRef;Ljava/util/Map;Lkotlin/jvm/internal/Ref$IntRef;Ljava/util/Map;Ljava/lang/CharSequence;Lkotlin/jvm/internal/Ref$ObjectRef;)Lkotlin/jvm/functions/Function1;
     290: iconst_1
     291: aconst_null
     292: invokestatic  #91                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
     295: aload         4
     297: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     300: checkcast     #93                 // class java/util/List
     303: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.sort:(Ljava/util/List;)V
     306: new           #101                // class java/lang/StringBuilder
     309: dup
     310: invokespecial #102                // Method java/lang/StringBuilder."<init>":()V
     313: ldc           #104                // String Syntax score:
     315: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     318: aload_3
     319: getfield      #111                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     322: invokevirtual #114                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     325: invokevirtual #117                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     328: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
     331: swap
     332: invokevirtual #129                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     335: new           #101                // class java/lang/StringBuilder
     338: dup
     339: invokespecial #102                // Method java/lang/StringBuilder."<init>":()V
     342: ldc           #131                // String Mid score:
     344: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     347: aload         4
     349: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     352: checkcast     #52                 // class java/util/ArrayList
     355: aload         4
     357: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     360: checkcast     #52                 // class java/util/ArrayList
     363: invokevirtual #135                // Method java/util/ArrayList.size:()I
     366: i2d
     367: ldc2_w        #136                // double 2.0d
     370: ddiv
     371: d2i
     372: invokevirtual #141                // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     375: checkcast     #143                // class java/lang/Number
     378: invokevirtual #147                // Method java/lang/Number.longValue:()J
     381: invokevirtual #150                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     384: invokevirtual #117                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     387: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
     390: swap
     391: invokevirtual #129                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     394: return

  public static final void new();
    Code:
       0: iconst_4
       1: anewarray     #15                 // class kotlin/Pair
       4: astore_1
       5: aload_1
       6: iconst_0
       7: bipush        41
       9: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      12: iconst_3
      13: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      16: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      19: aastore
      20: aload_1
      21: iconst_1
      22: bipush        93
      24: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      27: bipush        57
      29: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      35: aastore
      36: aload_1
      37: iconst_2
      38: bipush        125
      40: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      43: sipush        1197
      46: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      52: aastore
      53: aload_1
      54: iconst_3
      55: bipush        62
      57: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      60: sipush        25137
      63: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      69: aastore
      70: aload_1
      71: invokestatic  #38                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      74: astore_0
      75: iconst_4
      76: anewarray     #15                 // class kotlin/Pair
      79: astore_2
      80: aload_2
      81: iconst_0
      82: bipush        40
      84: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      87: bipush        41
      89: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      92: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      95: aastore
      96: aload_2
      97: iconst_1
      98: bipush        91
     100: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     103: bipush        93
     105: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     108: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: aastore
     112: aload_2
     113: iconst_2
     114: bipush        123
     116: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     119: bipush        125
     121: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     124: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     127: aastore
     128: aload_2
     129: iconst_3
     130: bipush        60
     132: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     135: bipush        62
     137: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     140: invokestatic  #32                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     143: aastore
     144: aload_2
     145: invokestatic  #38                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     148: astore_1
     149: aload_1
     150: invokeinterface #167,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     155: astore_2
     156: new           #44                 // class kotlin/jvm/internal/Ref$IntRef
     159: dup
     160: invokespecial #47                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     163: astore_3
     164: new           #49                 // class kotlin/jvm/internal/Ref$ObjectRef
     167: dup
     168: invokespecial #50                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
     171: astore        4
     173: aload         4
     175: new           #52                 // class java/util/ArrayList
     178: dup
     179: invokespecial #53                 // Method java/util/ArrayList."<init>":()V
     182: checkcast     #93                 // class java/util/List
     185: putfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     188: new           #49                 // class kotlin/jvm/internal/Ref$ObjectRef
     191: dup
     192: invokespecial #50                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
     195: astore        5
     197: aload         5
     199: new           #52                 // class java/util/ArrayList
     202: dup
     203: invokespecial #53                 // Method java/util/ArrayList."<init>":()V
     206: checkcast     #93                 // class java/util/List
     209: putfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     212: new           #62                 // class java/io/File
     215: dup
     216: getstatic     #11                 // Field INPUT:Ljava/lang/String;
     219: invokespecial #65                 // Method java/io/File."<init>":(Ljava/lang/String;)V
     222: aconst_null
     223: aload         5
     225: aload_2
     226: aload_1
     227: aload_3
     228: aload_0
     229: aload         4
     231: invokedynamic #175,  0            // InvokeDynamic #1:invoke:(Lkotlin/jvm/internal/Ref$ObjectRef;Ljava/util/Set;Ljava/util/Map;Lkotlin/jvm/internal/Ref$IntRef;Ljava/util/Map;Lkotlin/jvm/internal/Ref$ObjectRef;)Lkotlin/jvm/functions/Function1;
     236: iconst_1
     237: aconst_null
     238: invokestatic  #91                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
     241: new           #101                // class java/lang/StringBuilder
     244: dup
     245: invokespecial #102                // Method java/lang/StringBuilder."<init>":()V
     248: ldc           #104                // String Syntax score:
     250: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     253: aload_3
     254: getfield      #111                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     257: invokevirtual #114                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     260: ldc           #177                // String , Mid score:
     262: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     265: aload         4
     267: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     270: checkcast     #179                // class java/lang/Iterable
     273: invokestatic  #183                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     276: aload         4
     278: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     281: checkcast     #93                 // class java/util/List
     284: invokeinterface #184,  1          // InterfaceMethod java/util/List.size:()I
     289: i2d
     290: ldc2_w        #136                // double 2.0d
     293: ddiv
     294: d2i
     295: invokeinterface #185,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     300: checkcast     #143                // class java/lang/Number
     303: invokevirtual #147                // Method java/lang/Number.longValue:()J
     306: invokevirtual #150                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     309: invokevirtual #117                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     312: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
     315: swap
     316: invokevirtual #129                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     319: return

  public static final void main();
    Code:
       0: invokestatic  #191                // Method old:()V
       3: ldc           #193                // String ===================================
       5: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
       8: swap
       9: invokevirtual #129                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      12: invokestatic  #195                // Method new:()V
      15: return

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

  private static final kotlin.Unit old$lambda$0(kotlin.jvm.internal.Ref$ObjectRef, java.util.Map, kotlin.jvm.internal.Ref$IntRef, java.util.Map, java.lang.CharSequence, kotlin.jvm.internal.Ref$ObjectRef, java.lang.String);
    Code:
       0: aload         6
       2: ldc           #202                // String it
       4: invokestatic  #208                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      11: checkcast     #59                 // class java/util/ArrayDeque
      14: invokevirtual #211                // Method java/util/ArrayDeque.clear:()V
      17: lconst_0
      18: lstore        7
      20: iconst_0
      21: istore        9
      23: iconst_0
      24: istore        10
      26: aload         6
      28: invokevirtual #216                // Method java/lang/String.length:()I
      31: istore        11
      33: iload         10
      35: iload         11
      37: if_icmpge     249
      40: aload         6
      42: iload         10
      44: invokevirtual #220                // Method java/lang/String.charAt:(I)C
      47: istore        12
      49: aload_1
      50: iload         12
      52: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      55: invokestatic  #224                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      58: checkcast     #143                // class java/lang/Number
      61: invokevirtual #227                // Method java/lang/Number.intValue:()I
      64: istore        13
      66: iload         13
      68: istore        14
      70: iconst_0
      71: iload         14
      73: if_icmpgt     90
      76: iload         14
      78: iconst_4
      79: if_icmpge     86
      82: iconst_1
      83: goto          91
      86: iconst_0
      87: goto          91
      90: iconst_0
      91: ifeq          120
      94: aload_0
      95: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      98: checkcast     #59                 // class java/util/ArrayDeque
     101: iload         13
     103: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: invokevirtual #230                // Method java/util/ArrayDeque.push:(Ljava/lang/Object;)V
     109: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
     112: iload         12
     114: invokevirtual #234                // Method java/io/PrintStream.print:(C)V
     117: goto          243
     120: iconst_4
     121: iload         14
     123: if_icmpgt     141
     126: iload         14
     128: bipush        8
     130: if_icmpge     137
     133: iconst_1
     134: goto          142
     137: iconst_0
     138: goto          142
     141: iconst_0
     142: ifeq          243
     145: aload_0
     146: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     149: checkcast     #59                 // class java/util/ArrayDeque
     152: invokevirtual #238                // Method java/util/ArrayDeque.pop:()Ljava/lang/Object;
     155: checkcast     #23                 // class java/lang/Integer
     158: astore        15
     160: aload         15
     162: invokevirtual #239                // Method java/lang/Integer.intValue:()I
     165: iload         13
     167: iconst_4
     168: isub
     169: isub
     170: ifeq          235
     173: aload_2
     174: aload_2
     175: getfield      #111                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     178: aload_3
     179: iload         12
     181: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     184: invokestatic  #224                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     187: checkcast     #143                // class java/lang/Number
     190: invokevirtual #227                // Method java/lang/Number.intValue:()I
     193: iadd
     194: putfield      #111                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     197: iconst_1
     198: istore        9
     200: new           #101                // class java/lang/StringBuilder
     203: dup
     204: invokespecial #102                // Method java/lang/StringBuilder."<init>":()V
     207: ldc           #241                // String \u001b[31m
     209: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     212: iload         12
     214: invokevirtual #244                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     217: ldc           #246                // String \u001b[0m
     219: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     222: invokevirtual #117                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     225: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
     228: swap
     229: invokevirtual #248                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     232: goto          249
     235: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
     238: iload         12
     240: invokevirtual #234                // Method java/io/PrintStream.print:(C)V
     243: iinc          10, 1
     246: goto          33
     249: iload         9
     251: ifne          388
     254: aload_0
     255: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     258: checkcast     #59                 // class java/util/ArrayDeque
     261: invokevirtual #249                // Method java/util/ArrayDeque.size:()I
     264: istore        10
     266: iconst_0
     267: istore        11
     269: iload         10
     271: iconst_1
     272: isub
     273: istore        12
     275: iload         11
     277: iload         12
     279: if_icmpgt     371
     282: aload_0
     283: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     286: checkcast     #59                 // class java/util/ArrayDeque
     289: invokevirtual #238                // Method java/util/ArrayDeque.pop:()Ljava/lang/Object;
     292: checkcast     #143                // class java/lang/Number
     295: invokevirtual #227                // Method java/lang/Number.intValue:()I
     298: iconst_4
     299: iadd
     300: istore        13
     302: aload         4
     304: iload         13
     306: invokeinterface #250,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     311: istore        14
     313: lload         7
     315: iconst_5
     316: i2l
     317: lmul
     318: iload         13
     320: iconst_3
     321: isub
     322: i2l
     323: ladd
     324: lstore        7
     326: new           #101                // class java/lang/StringBuilder
     329: dup
     330: invokespecial #102                // Method java/lang/StringBuilder."<init>":()V
     333: ldc           #252                // String \u001b[32m
     335: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     338: iload         14
     340: invokevirtual #244                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     343: ldc           #246                // String \u001b[0m
     345: invokevirtual #108                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     348: invokevirtual #117                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     351: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
     354: swap
     355: invokevirtual #248                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     358: iload         11
     360: iload         12
     362: if_icmpeq     371
     365: iinc          11, 1
     368: goto          282
     371: aload         5
     373: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     376: checkcast     #52                 // class java/util/ArrayList
     379: lload         7
     381: invokestatic  #257                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     384: invokevirtual #261                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     387: pop
     388: bipush        10
     390: istore        10
     392: getstatic     #123                // Field java/lang/System.out:Ljava/io/PrintStream;
     395: iload         10
     397: invokevirtual #234                // Method java/io/PrintStream.print:(C)V
     400: getstatic     #267                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     403: areturn

  private static final kotlin.Unit new$lambda$3(kotlin.jvm.internal.Ref$ObjectRef, java.util.Set, java.util.Map, kotlin.jvm.internal.Ref$IntRef, java.util.Map, kotlin.jvm.internal.Ref$ObjectRef, java.lang.String);
    Code:
       0: aload         6
       2: ldc_w         #286                // String line
       5: invokestatic  #208                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       8: aload_0
       9: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      12: checkcast     #93                 // class java/util/List
      15: invokeinterface #287,  1          // InterfaceMethod java/util/List.clear:()V
      20: iconst_0
      21: istore        7
      23: aload         6
      25: invokevirtual #216                // Method java/lang/String.length:()I
      28: istore        8
      30: iload         7
      32: iload         8
      34: if_icmpge     191
      37: aload         6
      39: iload         7
      41: invokevirtual #220                // Method java/lang/String.charAt:(I)C
      44: istore        9
      46: aload_1
      47: iload         9
      49: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      52: invokeinterface #292,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      57: ifeq          81
      60: aload_0
      61: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      64: checkcast     #93                 // class java/util/List
      67: iload         9
      69: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      72: invokeinterface #293,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      77: pop
      78: goto          185
      81: iload         9
      83: aload_2
      84: aload_0
      85: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      88: checkcast     #93                 // class java/util/List
      91: invokestatic  #297                // Method kotlin/collections/CollectionsKt.lastOrNull:(Ljava/util/List;)Ljava/lang/Object;
      94: invokeinterface #299,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      99: checkcast     #17                 // class java/lang/Character
     102: dup
     103: ifnonnull     111
     106: pop
     107: pop
     108: goto          139
     111: invokevirtual #303                // Method java/lang/Character.charValue:()C
     114: if_icmpne     139
     117: aload_0
     118: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     121: checkcast     #93                 // class java/util/List
     124: invokeinterface #306,  1          // InterfaceMethod java/util/List.removeLast:()Ljava/lang/Object;
     129: astore        10
     131: aload         10
     133: invokestatic  #309                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     136: goto          185
     139: aload_3
     140: aload_3
     141: getfield      #111                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     144: aload         4
     146: iload         9
     148: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     151: invokeinterface #299,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     156: dup
     157: invokestatic  #309                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     160: checkcast     #143                // class java/lang/Number
     163: invokevirtual #227                // Method java/lang/Number.intValue:()I
     166: iadd
     167: putfield      #111                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     170: aload_0
     171: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     174: checkcast     #93                 // class java/util/List
     177: invokeinterface #287,  1          // InterfaceMethod java/util/List.clear:()V
     182: goto          191
     185: iinc          7, 1
     188: goto          30
     191: aload_0
     192: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     195: checkcast     #93                 // class java/util/List
     198: invokeinterface #184,  1          // InterfaceMethod java/util/List.size:()I
     203: ifle          442
     206: aload         5
     208: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     211: checkcast     #93                 // class java/util/List
     214: aload_0
     215: getfield      #57                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     218: checkcast     #179                // class java/lang/Iterable
     221: invokestatic  #312                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     224: checkcast     #179                // class java/lang/Iterable
     227: astore        7
     229: astore        17
     231: iconst_0
     232: istore        8
     234: aload         7
     236: astore        9
     238: new           #52                 // class java/util/ArrayList
     241: dup
     242: aload         7
     244: bipush        10
     246: invokestatic  #316                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     249: invokespecial #319                // Method java/util/ArrayList."<init>":(I)V
     252: checkcast     #321                // class java/util/Collection
     255: astore        10
     257: iconst_0
     258: istore        11
     260: aload         9
     262: invokeinterface #325,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     267: astore        12
     269: aload         12
     271: invokeinterface #331,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     276: ifeq          334
     279: aload         12
     281: invokeinterface #334,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     286: astore        13
     288: aload         10
     290: aload         13
     292: checkcast     #17                 // class java/lang/Character
     295: invokevirtual #303                // Method java/lang/Character.charValue:()C
     298: istore        14
     300: astore        18
     302: iconst_0
     303: istore        15
     305: aload_1
     306: checkcast     #179                // class java/lang/Iterable
     309: iload         14
     311: invokestatic  #21                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     314: invokestatic  #338                // Method kotlin/collections/CollectionsKt.indexOf:(Ljava/lang/Iterable;Ljava/lang/Object;)I
     317: iconst_1
     318: iadd
     319: invokestatic  #26                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     322: aload         18
     324: swap
     325: invokeinterface #339,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     330: pop
     331: goto          269
     334: aload         10
     336: checkcast     #93                 // class java/util/List
     339: nop
     340: aload         17
     342: swap
     343: checkcast     #179                // class java/lang/Iterable
     346: astore        7
     348: lconst_0
     349: invokestatic  #257                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     352: astore        8
     354: astore        17
     356: iconst_0
     357: istore        9
     359: aload         8
     361: astore        10
     363: aload         7
     365: invokeinterface #325,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     370: astore        11
     372: aload         11
     374: invokeinterface #331,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     379: ifeq          431
     382: aload         11
     384: invokeinterface #334,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     389: astore        12
     391: aload         10
     393: aload         12
     395: checkcast     #143                // class java/lang/Number
     398: invokevirtual #227                // Method java/lang/Number.intValue:()I
     401: istore        13
     403: checkcast     #143                // class java/lang/Number
     406: invokevirtual #147                // Method java/lang/Number.longValue:()J
     409: lstore        14
     411: iconst_0
     412: istore        16
     414: lload         14
     416: iconst_5
     417: i2l
     418: lmul
     419: iload         13
     421: i2l
     422: ladd
     423: invokestatic  #257                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     426: astore        10
     428: goto          372
     431: aload         10
     433: aload         17
     435: swap
     436: invokeinterface #293,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     441: pop
     442: getstatic     #267                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     445: areturn

  static {};
    Code:
       0: ldc_w         #361                // String input.txt
       3: putstatic     #11                 // Field INPUT:Ljava/lang/String;
       6: return
}


package org.linkedlist
class ListNode(var `val`: Int) {
     var next: ListNode? = null
}

fun deleteDuplicates(head: ListNode?): ListNode? {
    var node = head ?: return null
    while (node!!.next != null){
        if(node.`val` == node.next!!.`val`)
            node.next = node.next!!.next
        else
            node = node.next!!
    }
    return head
}

fun mergeTwoLists(list1: ListNode?, list2: ListNode?): ListNode? {
    var f = list1
    var s = list2
    var tail: ListNode? = null
    var mergedLL: ListNode? = null
    while (f != null && s != null){
        if (f.`val` < s.`val`){
            if (mergedLL == null){
                mergedLL = ListNode(f.`val`)
                tail = mergedLL
            }
            else{
                tail!!.next = ListNode(f.`val`)
                tail = tail.next
            }
            f = f.next
        }
        else{
            if (mergedLL == null){
                mergedLL = ListNode(s.`val`)
                tail = mergedLL
            }
            else{
                tail!!.next = ListNode(s.`val`)
                tail = tail.next
            }
            s = s.next
        }
    }
    if (f != null){
        while (f != null){
            if(tail == null){
                mergedLL = ListNode(f.`val`)
                tail = mergedLL
            }
            else{
                tail.next = ListNode(f.`val`)
                tail = tail.next
            }
            f = f.next
        }
    }
    if (s != null){
        while (s != null){
            if(tail == null){
                mergedLL = ListNode(s.`val`)
                tail = mergedLL
            }
            else{
                tail.next = ListNode(s.`val`)
                tail = tail.next
            }
            s = s.next
        }
    }
    return mergedLL
}

/* https://leetcode.com/problems/linked-list-cycle/
 */
fun hasCycle(head: ListNode?): Boolean {
    var fast = head
    var slow = head
    while (fast?.next != null){
        slow = slow!!.next
        fast = fast.next?.next
        if (fast == slow)
            return true
    }
    return false
}

// find length of cycle
fun lengthCycle(head: ListNode?): Int {
    var fast = head
    var slow = head
    while (fast?.next != null){
        slow = slow!!.next
        fast = fast.next?.next
        if (fast == slow){
            var length = 0
            do {
                length++
                slow = slow?.next
            }while (slow != fast)
        }
    }
    return 0
}

// https://leetcode.com/problems/linked-list-cycle-ii/
fun detectCycle(head: ListNode?): ListNode? {
    var fast = head
    var slow = head
    var length = 0
    while (fast?.next != null){
        slow = slow?.next
        fast = fast.next!!.next
        if (fast == slow){
            do {
                length++
                fast = fast?.next
            }while (fast != slow)
            break;
        }
    }

    if (length == 0)
        return null

    var first = head
    var second = head

    while (length > 0){
        second = second?.next
        length--
    }

    while (first != second){
        first = first?.next
        second = second?.next
    }

    return second
}

fun isHappy(n: Int): Boolean {
    var slow = n
    var fast = n
    do {
        slow = findSquare(slow)
        fast = findSquare(findSquare(fast))
    }while (fast != slow)

    return slow == 1
}

private fun findSquare(n: Int): Int{
    var ans = 0
    var num = n
    while  (num > 0){
        var rem = num % 10
        ans += rem * rem
        num /= 10
    }
    return ans
}

fun middleNode(head: ListNode?): ListNode? {
    var fast = head
    var slow = head
    while (fast?.next != null){
        slow = slow?.next
        fast = fast.next?.next
    }
    return slow
}

/*
https://leetcode.com/problems/reverse-linked-list/
in reversal
 */
fun reverseList(head: ListNode?): ListNode? {
    var prev: ListNode? = null
    var pres = head
    var next = head?.next
    while (pres != null){
        pres.next = prev
        prev = pres
        pres = next
        next = next?.next
    }
    return prev
}

// https://leetcode.com/problems/reverse-linked-list-ii/
fun reverseBetween(head: ListNode?, left: Int, right: Int): ListNode? {
    var h = head
    if (left == right)
        return head

    // skip the first left - 1 nodes
    var current = head
    var prev: ListNode? = null
    for (i in 0..<left - 1){
        prev = current
        current = current?.next
    }

    val last = prev
    val newEnd = current

    // reverse between left and right
    var next = current?.next
    for (i in 0 ..< right - left +1){
        current?.next = prev
        prev = current
        current = next
        next = next?.next
    }

    if (last != null)
        last.next = prev
    else
        h = prev

    newEnd?.next = current
    return h
}

fun isPalindrome(head: ListNode?): Boolean {

    var node = head
    // find middle
    var mid = middleNode(head)

    // reverse second half
    var secondHead = reverseList(mid)
    var reReverseHead = secondHead

    // compare
    while (node != null && secondHead != null){
        if (node.`val` != secondHead.`val`)
            break

        node = node.next
        secondHead = secondHead.next
    }

    // re-reverse
    reverseList(reReverseHead)

    return node == null || secondHead == null
}

fun reorderList(head: ListNode?): Unit {
    if(head?.next == null)
        return

    val mid = middleNode(head)
    var hs = reverseList(mid)
    var hf = head

    while (hf != null && hs != null){
        var temp = hf.next
        hf.next = hs
        hf = temp

        temp = hs.next
        hs.next = hf
        hs = temp
    }

    if (hf != null)
        hf.next = null
}

Compiled from "LinkedList.kt"
public final class org.linkedlist.LinkedListKt {
  public static final org.linkedlist.ListNode deleteDuplicates(org.linkedlist.ListNode);
    Code:
       0: aload_0
       1: dup
       2: ifnonnull     8
       5: pop
       6: aconst_null
       7: areturn
       8: astore_1
       9: aload_1
      10: dup
      11: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      14: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      17: ifnull        68
      20: aload_1
      21: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
      24: aload_1
      25: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      28: dup
      29: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      32: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
      35: if_icmpne     56
      38: aload_1
      39: aload_1
      40: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      43: dup
      44: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      47: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      50: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
      53: goto          9
      56: aload_1
      57: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      60: dup
      61: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      64: astore_1
      65: goto          9
      68: aload_0
      69: areturn

  public static final org.linkedlist.ListNode mergeTwoLists(org.linkedlist.ListNode, org.linkedlist.ListNode);
    Code:
       0: aload_0
       1: astore_2
       2: aload_1
       3: astore_3
       4: aconst_null
       5: astore        4
       7: aconst_null
       8: astore        5
      10: aload_2
      11: ifnull        149
      14: aload_3
      15: ifnull        149
      18: aload_2
      19: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
      22: aload_3
      23: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
      26: if_icmpge     89
      29: aload         5
      31: ifnonnull     54
      34: new           #15                 // class org/linkedlist/ListNode
      37: dup
      38: aload_2
      39: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
      42: invokespecial #36                 // Method org/linkedlist/ListNode."<init>":(I)V
      45: astore        5
      47: aload         5
      49: astore        4
      51: goto          81
      54: aload         4
      56: dup
      57: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      60: new           #15                 // class org/linkedlist/ListNode
      63: dup
      64: aload_2
      65: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
      68: invokespecial #36                 // Method org/linkedlist/ListNode."<init>":(I)V
      71: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
      74: aload         4
      76: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      79: astore        4
      81: aload_2
      82: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      85: astore_2
      86: goto          10
      89: aload         5
      91: ifnonnull     114
      94: new           #15                 // class org/linkedlist/ListNode
      97: dup
      98: aload_3
      99: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
     102: invokespecial #36                 // Method org/linkedlist/ListNode."<init>":(I)V
     105: astore        5
     107: aload         5
     109: astore        4
     111: goto          141
     114: aload         4
     116: dup
     117: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     120: new           #15                 // class org/linkedlist/ListNode
     123: dup
     124: aload_3
     125: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
     128: invokespecial #36                 // Method org/linkedlist/ListNode."<init>":(I)V
     131: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
     134: aload         4
     136: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     139: astore        4
     141: aload_3
     142: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     145: astore_3
     146: goto          10
     149: aload_2
     150: ifnull        213
     153: aload_2
     154: ifnull        213
     157: aload         4
     159: ifnonnull     182
     162: new           #15                 // class org/linkedlist/ListNode
     165: dup
     166: aload_2
     167: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
     170: invokespecial #36                 // Method org/linkedlist/ListNode."<init>":(I)V
     173: astore        5
     175: aload         5
     177: astore        4
     179: goto          205
     182: aload         4
     184: new           #15                 // class org/linkedlist/ListNode
     187: dup
     188: aload_2
     189: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
     192: invokespecial #36                 // Method org/linkedlist/ListNode."<init>":(I)V
     195: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
     198: aload         4
     200: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     203: astore        4
     205: aload_2
     206: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     209: astore_2
     210: goto          153
     213: aload_3
     214: ifnull        277
     217: aload_3
     218: ifnull        277
     221: aload         4
     223: ifnonnull     246
     226: new           #15                 // class org/linkedlist/ListNode
     229: dup
     230: aload_3
     231: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
     234: invokespecial #36                 // Method org/linkedlist/ListNode."<init>":(I)V
     237: astore        5
     239: aload         5
     241: astore        4
     243: goto          269
     246: aload         4
     248: new           #15                 // class org/linkedlist/ListNode
     251: dup
     252: aload_3
     253: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
     256: invokespecial #36                 // Method org/linkedlist/ListNode."<init>":(I)V
     259: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
     262: aload         4
     264: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     267: astore        4
     269: aload_3
     270: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     273: astore_3
     274: goto          217
     277: aload         5
     279: areturn

  public static final boolean hasCycle(org.linkedlist.ListNode);
    Code:
       0: aload_0
       1: astore_1
       2: aload_0
       3: astore_2
       4: aload_1
       5: dup
       6: ifnull        15
       9: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      12: goto          17
      15: pop
      16: aconst_null
      17: ifnull        56
      20: aload_2
      21: dup
      22: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      25: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      28: astore_2
      29: aload_1
      30: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      33: dup
      34: ifnull        43
      37: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      40: goto          45
      43: pop
      44: aconst_null
      45: astore_1
      46: aload_1
      47: aload_2
      48: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      51: ifeq          4
      54: iconst_1
      55: ireturn
      56: iconst_0
      57: ireturn

  public static final int lengthCycle(org.linkedlist.ListNode);
    Code:
       0: aload_0
       1: astore_1
       2: aload_0
       3: astore_2
       4: aload_1
       5: dup
       6: ifnull        15
       9: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      12: goto          17
      15: pop
      16: aconst_null
      17: ifnull        84
      20: aload_2
      21: dup
      22: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      25: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      28: astore_2
      29: aload_1
      30: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      33: dup
      34: ifnull        43
      37: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      40: goto          45
      43: pop
      44: aconst_null
      45: astore_1
      46: aload_1
      47: aload_2
      48: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      51: ifeq          4
      54: iconst_0
      55: istore_3
      56: iinc          3, 1
      59: aload_2
      60: dup
      61: ifnull        70
      64: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      67: goto          72
      70: pop
      71: aconst_null
      72: astore_2
      73: aload_2
      74: aload_1
      75: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      78: ifeq          56
      81: goto          4
      84: iconst_0
      85: ireturn

  public static final org.linkedlist.ListNode detectCycle(org.linkedlist.ListNode);
    Code:
       0: aload_0
       1: astore_1
       2: aload_0
       3: astore_2
       4: iconst_0
       5: istore_3
       6: aload_1
       7: dup
       8: ifnull        17
      11: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      14: goto          19
      17: pop
      18: aconst_null
      19: ifnull        84
      22: aload_2
      23: dup
      24: ifnull        33
      27: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      30: goto          35
      33: pop
      34: aconst_null
      35: astore_2
      36: aload_1
      37: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      40: dup
      41: invokestatic  #13                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      44: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      47: astore_1
      48: aload_1
      49: aload_2
      50: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      53: ifeq          6
      56: iinc          3, 1
      59: aload_1
      60: dup
      61: ifnull        70
      64: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      67: goto          72
      70: pop
      71: aconst_null
      72: astore_1
      73: aload_1
      74: aload_2
      75: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      78: ifeq          56
      81: goto          84
      84: iload_3
      85: ifne          90
      88: aconst_null
      89: areturn
      90: aload_0
      91: astore        4
      93: aload_0
      94: astore        5
      96: iload_3
      97: ifle          122
     100: aload         5
     102: dup
     103: ifnull        112
     106: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     109: goto          114
     112: pop
     113: aconst_null
     114: astore        5
     116: iinc          3, -1
     119: goto          96
     122: aload         4
     124: aload         5
     126: invokestatic  #48                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     129: ifne          167
     132: aload         4
     134: dup
     135: ifnull        144
     138: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     141: goto          146
     144: pop
     145: aconst_null
     146: astore        4
     148: aload         5
     150: dup
     151: ifnull        160
     154: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     157: goto          162
     160: pop
     161: aconst_null
     162: astore        5
     164: goto          122
     167: aload         5
     169: areturn

  public static final boolean isHappy(int);
    Code:
       0: iload_0
       1: istore_1
       2: iload_0
       3: istore_2
       4: iload_1
       5: invokestatic  #63                 // Method findSquare:(I)I
       8: istore_1
       9: iload_2
      10: invokestatic  #63                 // Method findSquare:(I)I
      13: invokestatic  #63                 // Method findSquare:(I)I
      16: istore_2
      17: iload_2
      18: iload_1
      19: if_icmpne     4
      22: iload_1
      23: iconst_1
      24: if_icmpne     31
      27: iconst_1
      28: goto          32
      31: iconst_0
      32: ireturn

  private static final int findSquare(int);
    Code:
       0: iconst_0
       1: istore_1
       2: iload_0
       3: istore_2
       4: iload_2
       5: ifle          27
       8: iload_2
       9: bipush        10
      11: irem
      12: istore_3
      13: iload_1
      14: iload_3
      15: iload_3
      16: imul
      17: iadd
      18: istore_1
      19: iload_2
      20: bipush        10
      22: idiv
      23: istore_2
      24: goto          4
      27: iload_1
      28: ireturn

  public static final org.linkedlist.ListNode middleNode(org.linkedlist.ListNode);
    Code:
       0: aload_0
       1: astore_1
       2: aload_0
       3: astore_2
       4: aload_1
       5: dup
       6: ifnull        15
       9: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      12: goto          17
      15: pop
      16: aconst_null
      17: ifnull        54
      20: aload_2
      21: dup
      22: ifnull        31
      25: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      28: goto          33
      31: pop
      32: aconst_null
      33: astore_2
      34: aload_1
      35: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      38: dup
      39: ifnull        48
      42: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      45: goto          50
      48: pop
      49: aconst_null
      50: astore_1
      51: goto          4
      54: aload_2
      55: areturn

  public static final org.linkedlist.ListNode reverseList(org.linkedlist.ListNode);
    Code:
       0: aconst_null
       1: astore_1
       2: aload_0
       3: astore_2
       4: aload_0
       5: dup
       6: ifnull        15
       9: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      12: goto          17
      15: pop
      16: aconst_null
      17: astore_3
      18: aload_2
      19: ifnull        48
      22: aload_2
      23: aload_1
      24: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
      27: aload_2
      28: astore_1
      29: aload_3
      30: astore_2
      31: aload_3
      32: dup
      33: ifnull        42
      36: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      39: goto          44
      42: pop
      43: aconst_null
      44: astore_3
      45: goto          18
      48: aload_1
      49: areturn

  public static final org.linkedlist.ListNode reverseBetween(org.linkedlist.ListNode, int, int);
    Code:
       0: aload_0
       1: astore_3
       2: iload_1
       3: iload_2
       4: if_icmpne     9
       7: aload_0
       8: areturn
       9: aload_0
      10: astore        4
      12: aconst_null
      13: astore        5
      15: iconst_0
      16: istore        6
      18: iload_1
      19: iconst_1
      20: isub
      21: istore        7
      23: iload         6
      25: iload         7
      27: if_icmpge     56
      30: aload         4
      32: astore        5
      34: aload         4
      36: dup
      37: ifnull        46
      40: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      43: goto          48
      46: pop
      47: aconst_null
      48: astore        4
      50: iinc          6, 1
      53: goto          23
      56: aload         5
      58: astore        6
      60: aload         4
      62: astore        7
      64: aload         4
      66: dup
      67: ifnull        76
      70: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      73: goto          78
      76: pop
      77: aconst_null
      78: astore        8
      80: iconst_0
      81: istore        9
      83: iload_2
      84: iload_1
      85: isub
      86: iconst_1
      87: iadd
      88: istore        10
      90: iload         9
      92: iload         10
      94: if_icmpge     142
      97: aload         4
      99: dup
     100: ifnull        111
     103: aload         5
     105: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
     108: goto          112
     111: pop
     112: aload         4
     114: astore        5
     116: aload         8
     118: astore        4
     120: aload         8
     122: dup
     123: ifnull        132
     126: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
     129: goto          134
     132: pop
     133: aconst_null
     134: astore        8
     136: iinc          9, 1
     139: goto          90
     142: aload         6
     144: ifnull        157
     147: aload         6
     149: aload         5
     151: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
     154: goto          160
     157: aload         5
     159: astore_3
     160: aload         7
     162: dup
     163: ifnull        174
     166: aload         4
     168: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
     171: goto          175
     174: pop
     175: aload_3
     176: areturn

  public static final boolean isPalindrome(org.linkedlist.ListNode);
    Code:
       0: aload_0
       1: astore_1
       2: aload_0
       3: invokestatic  #84                 // Method middleNode:(Lorg/linkedlist/ListNode;)Lorg/linkedlist/ListNode;
       6: astore_2
       7: aload_2
       8: invokestatic  #86                 // Method reverseList:(Lorg/linkedlist/ListNode;)Lorg/linkedlist/ListNode;
      11: astore_3
      12: aload_3
      13: astore        4
      15: aload_1
      16: ifnull        50
      19: aload_3
      20: ifnull        50
      23: aload_1
      24: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
      27: aload_3
      28: invokevirtual #23                 // Method org/linkedlist/ListNode.getVal:()I
      31: if_icmpeq     37
      34: goto          50
      37: aload_1
      38: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      41: astore_1
      42: aload_3
      43: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      46: astore_3
      47: goto          15
      50: aload         4
      52: invokestatic  #86                 // Method reverseList:(Lorg/linkedlist/ListNode;)Lorg/linkedlist/ListNode;
      55: pop
      56: aload_1
      57: ifnull        64
      60: aload_3
      61: ifnonnull     68
      64: iconst_1
      65: goto          69
      68: iconst_0
      69: ireturn

  public static final void reorderList(org.linkedlist.ListNode);
    Code:
       0: aload_0
       1: dup
       2: ifnull        11
       5: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
       8: goto          13
      11: pop
      12: aconst_null
      13: ifnonnull     17
      16: return
      17: aload_0
      18: invokestatic  #84                 // Method middleNode:(Lorg/linkedlist/ListNode;)Lorg/linkedlist/ListNode;
      21: astore_1
      22: aload_1
      23: invokestatic  #86                 // Method reverseList:(Lorg/linkedlist/ListNode;)Lorg/linkedlist/ListNode;
      26: astore_2
      27: aload_0
      28: astore_3
      29: aload_3
      30: ifnull        68
      33: aload_2
      34: ifnull        68
      37: aload_3
      38: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      41: astore        4
      43: aload_3
      44: aload_2
      45: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
      48: aload         4
      50: astore_3
      51: aload_2
      52: invokevirtual #19                 // Method org/linkedlist/ListNode.getNext:()Lorg/linkedlist/ListNode;
      55: astore        4
      57: aload_2
      58: aload_3
      59: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
      62: aload         4
      64: astore_2
      65: goto          29
      68: aload_3
      69: ifnull        77
      72: aload_3
      73: aconst_null
      74: invokevirtual #27                 // Method org/linkedlist/ListNode.setNext:(Lorg/linkedlist/ListNode;)V
      77: return
}


package org.slidingwindow

import kotlin.math.abs

// https://leetcode.com/problems/minimum-size-subarray-sum/
fun minSubArrayLen(target: Int, nums: IntArray): Int {
    var i = 0; var j = 0; var sum = 0; var min = Int.MAX_VALUE
    while (j < nums.size){
        sum += nums[j]
        if (sum >= target){
            while (sum >= target){
                min = Math.min(min, j - i + 1)
                sum -= nums[i]
                i++
            }
        }
        j++
    }
    return  if (min == Int.MAX_VALUE) 0 else min
}

fun findClosestElements(arr: IntArray, k: Int, x: Int): List<Int> {
    var i = 0; var j =  0
    // create map with key as diff and value as list of elements
    val map = sortedMapOf<Int, MutableList<Int>>()
    while(j < arr.size){
        val diff = Math.abs(arr[j] - x)
        if (map.containsKey(diff)){
            map[diff]?.add(arr[j])
        }
        else{
            map.put(diff, mutableListOf(arr[j]))
        }
        j++
    }
    var rem = k
    val ans = mutableListOf<Int>()
    for (key in map.keys){
        while (rem > 0){
            map[key]?.let { it ->
                if (it.size > 1){
                    ans.add(it.removeAt(0))
                    rem--
                }
            }
        }
    }

    return ans.sorted()
}
fun containsNearbyDuplicate(nums: IntArray, k: Int): Boolean {
    var i = 0; var j = 0
    val set = mutableSetOf<Int>()
    while (j < nums.size){
        if (set.contains(nums[j]))
            return true
        set.add(nums[j])
        if (j - i + 1> k){
            set.remove(nums[i])
            i++
        }
        j++
    }
    return false
}

fun checkInclusion(s1: String, s2: String): Boolean {
    val mapForS1 = hashMapOf<Char, Int>()
    val mapForS2 = hashMapOf<Char, Int>()
    val k = s1.length
    for (c in s1.toCharArray())
        mapForS1[c] = mapForS1.getOrDefault(c, 0) + 1

    var count = mapForS1.size
    var i = 0
    var j = 0

    while (j < s2.length){
        val current = s2[j]
        mapForS2.put(current, mapForS2.getOrDefault(current, 0) + 1)

        if (j -i + 1 < k)
            j++

        else if (j - i + 1 == k){
            if(compareMaps(mapForS1, mapForS2))
                return true
            else{
                mapForS2.put(s2[i], mapForS2.get(s2[i])!! - 1)
                if(mapForS2.get(s2[i]) == 0)
                    mapForS2.remove(s2[i])
                i++
                j++
            }
        }
    }
    return false
}

private fun compareMaps(map1 : Map<Char, Int>, map2: Map<Char, Int>): Boolean {
    for (key in map1.keys){
        if (! (map2.containsKey(key) && map2.get(key) == map1.get(key)))
            return false
    }
    return true
}

fun main() {
    checkInclusion("adc", "dcda")
}

Compiled from "SlidingWindowNeet.kt"
public final class org.slidingwindow.SlidingWindowNeetKt {
  public static final int minSubArrayLen(int, int[]);
    Code:
       0: aload_1
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: iconst_0
      11: istore        4
      13: ldc           #16                 // int 2147483647
      15: istore        5
      17: iload_3
      18: aload_1
      19: arraylength
      20: if_icmpge     75
      23: iload         4
      25: aload_1
      26: iload_3
      27: iaload
      28: iadd
      29: istore        4
      31: iload         4
      33: iload_0
      34: if_icmplt     69
      37: iload         4
      39: iload_0
      40: if_icmplt     69
      43: iload         5
      45: iload_3
      46: iload_2
      47: isub
      48: iconst_1
      49: iadd
      50: invokestatic  #22                 // Method java/lang/Math.min:(II)I
      53: istore        5
      55: iload         4
      57: aload_1
      58: iload_2
      59: iaload
      60: isub
      61: istore        4
      63: iinc          2, 1
      66: goto          37
      69: iinc          3, 1
      72: goto          17
      75: iload         5
      77: ldc           #16                 // int 2147483647
      79: if_icmpne     86
      82: iconst_0
      83: goto          88
      86: iload         5
      88: ireturn

  public static final java.util.List<java.lang.Integer> findClosestElements(int[], int, int);
    Code:
       0: aload_0
       1: ldc           #34                 // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_3
       8: iconst_0
       9: istore        4
      11: iconst_0
      12: anewarray     #36                 // class kotlin/Pair
      15: invokestatic  #42                 // Method kotlin/collections/MapsKt.sortedMapOf:([Lkotlin/Pair;)Ljava/util/SortedMap;
      18: astore        5
      20: iload         4
      22: aload_0
      23: arraylength
      24: if_icmpge     133
      27: aload_0
      28: iload         4
      30: iaload
      31: iload_2
      32: isub
      33: invokestatic  #46                 // Method java/lang/Math.abs:(I)I
      36: istore        6
      38: aload         5
      40: iload         6
      42: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: invokeinterface #58,  2           // InterfaceMethod java/util/SortedMap.containsKey:(Ljava/lang/Object;)Z
      50: ifeq          92
      53: aload         5
      55: iload         6
      57: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      60: invokeinterface #62,  2           // InterfaceMethod java/util/SortedMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      65: checkcast     #64                 // class java/util/List
      68: dup
      69: ifnull        88
      72: aload_0
      73: iload         4
      75: iaload
      76: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: invokeinterface #67,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      84: pop
      85: goto          127
      88: pop
      89: goto          127
      92: aload         5
      94: iload         6
      96: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: iconst_1
     100: anewarray     #48                 // class java/lang/Integer
     103: astore        7
     105: aload         7
     107: iconst_0
     108: aload_0
     109: iload         4
     111: iaload
     112: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     115: aastore
     116: aload         7
     118: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
     121: invokeinterface #77,  3           // InterfaceMethod java/util/SortedMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     126: pop
     127: iinc          4, 1
     130: goto          20
     133: iconst_0
     134: istore        6
     136: iload_1
     137: istore        6
     139: new           #79                 // class java/util/ArrayList
     142: dup
     143: invokespecial #83                 // Method java/util/ArrayList."<init>":()V
     146: checkcast     #64                 // class java/util/List
     149: astore        7
     151: aload         5
     153: invokeinterface #87,  1           // InterfaceMethod java/util/SortedMap.keySet:()Ljava/util/Set;
     158: invokeinterface #93,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     163: astore        8
     165: aload         8
     167: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     172: ifeq          254
     175: aload         8
     177: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     182: checkcast     #48                 // class java/lang/Integer
     185: astore        9
     187: iload         6
     189: ifle          165
     192: aload         5
     194: aload         9
     196: invokeinterface #62,  2           // InterfaceMethod java/util/SortedMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     201: checkcast     #64                 // class java/util/List
     204: dup
     205: ifnull        250
     208: astore        10
     210: iconst_0
     211: istore        11
     213: aload         10
     215: invokeinterface #107,  1          // InterfaceMethod java/util/List.size:()I
     220: iconst_1
     221: if_icmple     246
     224: aload         7
     226: aload         10
     228: iconst_0
     229: invokeinterface #111,  2          // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
     234: invokeinterface #67,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     239: pop
     240: iload         6
     242: iconst_m1
     243: iadd
     244: istore        6
     246: nop
     247: goto          187
     250: pop
     251: goto          187
     254: aload         7
     256: checkcast     #113                // class java/lang/Iterable
     259: invokestatic  #117                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     262: areturn

  public static final boolean containsNearbyDuplicate(int[], int);
    Code:
       0: aload_0
       1: ldc           #9                  // String nums
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: new           #133                // class java/util/LinkedHashSet
      13: dup
      14: invokespecial #134                // Method java/util/LinkedHashSet."<init>":()V
      17: checkcast     #89                 // class java/util/Set
      20: astore        4
      22: iload_3
      23: aload_0
      24: arraylength
      25: if_icmpge     92
      28: aload         4
      30: aload_0
      31: iload_3
      32: iaload
      33: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: invokeinterface #137,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      41: ifeq          46
      44: iconst_1
      45: ireturn
      46: aload         4
      48: aload_0
      49: iload_3
      50: iaload
      51: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: invokeinterface #138,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      59: pop
      60: iload_3
      61: iload_2
      62: isub
      63: iconst_1
      64: iadd
      65: iload_1
      66: if_icmple     86
      69: aload         4
      71: aload_0
      72: iload_2
      73: iaload
      74: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      77: invokeinterface #140,  2          // InterfaceMethod java/util/Set.remove:(Ljava/lang/Object;)Z
      82: pop
      83: iinc          2, 1
      86: iinc          3, 1
      89: goto          22
      92: iconst_0
      93: ireturn

  public static final boolean checkInclusion(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #146                // String s1
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #148                // String s2
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #150                // class java/util/HashMap
      15: dup
      16: invokespecial #151                // Method java/util/HashMap."<init>":()V
      19: astore_2
      20: new           #150                // class java/util/HashMap
      23: dup
      24: invokespecial #151                // Method java/util/HashMap."<init>":()V
      27: astore_3
      28: aload_0
      29: invokevirtual #156                // Method java/lang/String.length:()I
      32: istore        4
      34: aload_0
      35: invokevirtual #160                // Method java/lang/String.toCharArray:()[C
      38: dup
      39: ldc           #162                // String toCharArray(...)
      41: invokestatic  #165                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      44: astore        5
      46: iconst_0
      47: istore        6
      49: aload         5
      51: arraylength
      52: istore        7
      54: iload         6
      56: iload         7
      58: if_icmpge     117
      61: aload         5
      63: iload         6
      65: caload
      66: istore        8
      68: iload         8
      70: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      73: astore        9
      75: aload_2
      76: checkcast     #172                // class java/util/Map
      79: aload         9
      81: aload_2
      82: iload         8
      84: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      87: iconst_0
      88: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: invokevirtual #175                // Method java/util/HashMap.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      94: checkcast     #177                // class java/lang/Number
      97: invokevirtual #180                // Method java/lang/Number.intValue:()I
     100: iconst_1
     101: iadd
     102: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: invokeinterface #181,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     110: pop
     111: iinc          6, 1
     114: goto          54
     117: aload_2
     118: invokevirtual #182                // Method java/util/HashMap.size:()I
     121: istore        5
     123: iconst_0
     124: istore        6
     126: iconst_0
     127: istore        7
     129: iload         7
     131: aload_1
     132: invokevirtual #156                // Method java/lang/String.length:()I
     135: if_icmpge     321
     138: aload_1
     139: iload         7
     141: invokevirtual #186                // Method java/lang/String.charAt:(I)C
     144: istore        8
     146: aload_3
     147: iload         8
     149: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     152: aload_3
     153: iload         8
     155: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     158: iconst_0
     159: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     162: invokevirtual #175                // Method java/util/HashMap.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     165: checkcast     #177                // class java/lang/Number
     168: invokevirtual #180                // Method java/lang/Number.intValue:()I
     171: iconst_1
     172: iadd
     173: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     176: invokevirtual #187                // Method java/util/HashMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     179: pop
     180: iload         7
     182: iload         6
     184: isub
     185: iconst_1
     186: iadd
     187: iload         4
     189: if_icmpge     198
     192: iinc          7, 1
     195: goto          129
     198: iload         7
     200: iload         6
     202: isub
     203: iconst_1
     204: iadd
     205: iload         4
     207: if_icmpne     129
     210: aload_2
     211: checkcast     #172                // class java/util/Map
     214: aload_3
     215: checkcast     #172                // class java/util/Map
     218: invokestatic  #191                // Method compareMaps:(Ljava/util/Map;Ljava/util/Map;)Z
     221: ifeq          226
     224: iconst_1
     225: ireturn
     226: aload_3
     227: aload_1
     228: iload         6
     230: invokevirtual #186                // Method java/lang/String.charAt:(I)C
     233: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     236: aload_3
     237: aload_1
     238: iload         6
     240: invokevirtual #186                // Method java/lang/String.charAt:(I)C
     243: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     246: invokevirtual #192                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     249: dup
     250: invokestatic  #196                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     253: checkcast     #177                // class java/lang/Number
     256: invokevirtual #180                // Method java/lang/Number.intValue:()I
     259: iconst_1
     260: isub
     261: invokestatic  #52                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     264: invokevirtual #187                // Method java/util/HashMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     267: pop
     268: aload_3
     269: aload_1
     270: iload         6
     272: invokevirtual #186                // Method java/lang/String.charAt:(I)C
     275: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     278: invokevirtual #192                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     281: checkcast     #48                 // class java/lang/Integer
     284: dup
     285: ifnonnull     292
     288: pop
     289: goto          312
     292: invokevirtual #197                // Method java/lang/Integer.intValue:()I
     295: ifne          312
     298: aload_3
     299: aload_1
     300: iload         6
     302: invokevirtual #186                // Method java/lang/String.charAt:(I)C
     305: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     308: invokevirtual #199                // Method java/util/HashMap.remove:(Ljava/lang/Object;)Ljava/lang/Object;
     311: pop
     312: iinc          6, 1
     315: iinc          7, 1
     318: goto          129
     321: iconst_0
     322: ireturn

  private static final boolean compareMaps(java.util.Map<java.lang.Character, java.lang.Integer>, java.util.Map<java.lang.Character, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokeinterface #211,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
       6: invokeinterface #93,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      11: astore_2
      12: aload_2
      13: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      18: ifeq          75
      21: aload_2
      22: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      27: checkcast     #167                // class java/lang/Character
      30: invokevirtual #215                // Method java/lang/Character.charValue:()C
      33: istore_3
      34: aload_1
      35: iload_3
      36: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      39: invokeinterface #216,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      44: ifeq          73
      47: aload_1
      48: iload_3
      49: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      52: invokeinterface #217,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      57: aload_0
      58: iload_3
      59: invokestatic  #170                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      62: invokeinterface #217,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      67: invokestatic  #221                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      70: ifne          12
      73: iconst_0
      74: ireturn
      75: iconst_1
      76: ireturn

  public static final void main();
    Code:
       0: ldc           #227                // String adc
       2: ldc           #229                // String dcda
       4: invokestatic  #231                // Method checkInclusion:(Ljava/lang/String;Ljava/lang/String;)Z
       7: pop
       8: return

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