package name.valery1707.problem.leet.code

/**
 * # 13. Roman to Integer
 *
 * Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
 *
 * | Symbol | Value |
 * |--------|-------|
 * | `I` | `1` |
 * | `V` | `5` |
 * | `X` | `10` |
 * | `L` | `50` |
 * | `C` | `100` |
 * | `D` | `500` |
 * | `M` | `1000` |
 *
 * For example, `2` is written as `II` in Roman numeral, just two ones added together.
 * `12` is written as `XII`, which is simply `X + II`.
 * The number `27` is written as `XXVII`, which is `XX + V + II`.
 *
 * Roman numerals are usually written largest to smallest from left to right.
 * However, the numeral for four is not `IIII`.
 * Instead, the number four is written as `IV`.
 * Because the one is before the five we subtract it making four.
 * The same principle applies to the number nine, which is written as `IX`.
 * There are six instances where subtraction is used:
 * * `I` can be placed before `V` (`5`) and `X` (`10`) to make `4` and `9`.
 * * `X` can be placed before `L` (`50`) and `C` (`100`) to make `40` and `90`.
 * * `C` can be placed before `D` (`500`) and `M` (`1000`) to make `400` and `900`.
 *
 * Given a roman numeral, convert it to an integer.
 *
 * ### Constraints
 * * `1 <= s.length <= 15`
 * * `s` contains only the characters (`'I', 'V', 'X', 'L', 'C', 'D', 'M'`)
 * * It is **guaranteed** that `s` is a valid roman numeral in the range `[1, 3999]`
 *
 * 13. Roman to Integer
 */
interface RomanToIntegerK {
    fun romanToInt(s: String): Int

    @Suppress("EnumEntryName", "unused")
    enum class Implementation : RomanToIntegerK {
        /**
         * Parse only valid values.
         */
        maps {
            //Should be static
            private val values = mapOf('I' to 1, 'V' to 5, 'X' to 10, 'L' to 50, 'C' to 100, 'D' to 500, 'M' to 1000)
            private val prefix = mapOf('I' to setOf('V', 'X'), 'X' to setOf('L', 'C'), 'C' to setOf('D', 'M'))
            override fun romanToInt(s: String): Int {
                val max = s.length - 1
                var sum = 0
                var i = 0
                while (i <= max) {
                    val c = s[i]
                    sum += if (c in prefix && i < max && s[i + 1] in prefix[c]!!) {
                        values[s[++i]]!! - values[c]!!
                    } else {
                        values[c]!!
                    }
                    i++
                }
                return sum
            }
        },

        /**
         * Logic:
         * * Parse valid `IV`:
         *     * `prev == 0 && curr == 5 => sum = 0 + 5`
         *     * `prev == 5 && curr == 1 => sum = 5 - 1`
         *     * `sum == 4`
         * * Parse also invalid `IM`:
         *     * `prev == 0 && curr == 1000 => sum = 0 + 1000`
         *     * `prev == 1000 && curr == 1 => sum = 1000 - 1`
         *     * `sum == 999`
         */
        switch {
            override fun romanToInt(s: String): Int {
                var sum = 0
                var prev = 0
                for (i in (s.length - 1).downTo(0)) {
                    val curr = when (s[i]) {
                        'I' -> 1
                        'V' -> 5
                        'X' -> 10
                        'L' -> 50
                        'C' -> 100
                        'D' -> 500
                        'M' -> 1000
                        else -> 0
                    }
                    sum += if (curr >= prev) curr else -curr
                    prev = curr
                }
                return sum
            }
        },
    }
}

Compiled from "RomanToIntegerK.kt"
public abstract class name.valery1707.problem.leet.code.RomanToIntegerK$Implementation extends java.lang.Enum<name.valery1707.problem.leet.code.RomanToIntegerK$Implementation> implements name.valery1707.problem.leet.code.RomanToIntegerK {
  public static final name.valery1707.problem.leet.code.RomanToIntegerK$Implementation maps;

  public static final name.valery1707.problem.leet.code.RomanToIntegerK$Implementation switch;

  private static final name.valery1707.problem.leet.code.RomanToIntegerK$Implementation[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private name.valery1707.problem.leet.code.RomanToIntegerK$Implementation();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #12                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: return

  public static name.valery1707.problem.leet.code.RomanToIntegerK$Implementation[] values();
    Code:
       0: getstatic     #24                 // Field $VALUES:[Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;
       3: invokevirtual #30                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #31                 // class "[Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;"
       9: areturn

  public static name.valery1707.problem.leet.code.RomanToIntegerK$Implementation valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class name/valery1707/problem/leet/code/RomanToIntegerK$Implementation
       2: aload_0
       3: invokestatic  #36                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class name/valery1707/problem/leet/code/RomanToIntegerK$Implementation
       9: areturn

  public static kotlin.enums.EnumEntries<name.valery1707.problem.leet.code.RomanToIntegerK$Implementation> getEntries();
    Code:
       0: getstatic     #45                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final name.valery1707.problem.leet.code.RomanToIntegerK$Implementation[] $values();
    Code:
       0: iconst_2
       1: anewarray     #2                  // class name/valery1707/problem/leet/code/RomanToIntegerK$Implementation
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #49                 // Field maps:Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #52                 // Field switch:Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;
      16: aastore
      17: aload_0
      18: areturn

  public name.valery1707.problem.leet.code.RomanToIntegerK$Implementation(java.lang.String, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #54                 // Method "<init>":(Ljava/lang/String;I)V
       6: return

  static {};
    Code:
       0: new           #59                 // class name/valery1707/problem/leet/code/RomanToIntegerK$Implementation$maps
       3: dup
       4: ldc           #60                 // String maps
       6: iconst_0
       7: invokespecial #61                 // Method name/valery1707/problem/leet/code/RomanToIntegerK$Implementation$maps."<init>":(Ljava/lang/String;I)V
      10: putstatic     #49                 // Field maps:Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;
      13: new           #63                 // class name/valery1707/problem/leet/code/RomanToIntegerK$Implementation$switch
      16: dup
      17: ldc           #64                 // String switch
      19: iconst_1
      20: invokespecial #65                 // Method name/valery1707/problem/leet/code/RomanToIntegerK$Implementation$switch."<init>":(Ljava/lang/String;I)V
      23: putstatic     #52                 // Field switch:Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;
      26: invokestatic  #67                 // Method $values:()[Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;
      29: putstatic     #24                 // Field $VALUES:[Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;
      32: getstatic     #24                 // Field $VALUES:[Lname/valery1707/problem/leet/code/RomanToIntegerK$Implementation;
      35: checkcast     #69                 // class "[Ljava/lang/Enum;"
      38: invokestatic  #75                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      41: putstatic     #45                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      44: return
}

Compiled from "RomanToIntegerK.kt"
final class name.valery1707.problem.leet.code.RomanToIntegerK$Implementation$maps extends name.valery1707.problem.leet.code.RomanToIntegerK$Implementation {
  private final java.util.Map<java.lang.Character, java.lang.Integer> values;

  private final java.util.Map<java.lang.Character, java.util.Set<java.lang.Character>> prefix;

  name.valery1707.problem.leet.code.RomanToIntegerK$Implementation$maps();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: aconst_null
       4: invokespecial #10                 // Method name/valery1707/problem/leet/code/RomanToIntegerK$Implementation."<init>":(Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
       7: aload_0
       8: bipush        7
      10: anewarray     #12                 // class kotlin/Pair
      13: astore_3
      14: aload_3
      15: iconst_0
      16: bipush        73
      18: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      21: iconst_1
      22: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      28: aastore
      29: aload_3
      30: iconst_1
      31: bipush        86
      33: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      36: iconst_5
      37: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      43: aastore
      44: aload_3
      45: iconst_2
      46: bipush        88
      48: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      51: bipush        10
      53: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      56: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      59: aastore
      60: aload_3
      61: iconst_3
      62: bipush        76
      64: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      67: bipush        50
      69: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      75: aastore
      76: aload_3
      77: iconst_4
      78: bipush        67
      80: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      83: bipush        100
      85: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      91: aastore
      92: aload_3
      93: iconst_5
      94: bipush        68
      96: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      99: sipush        500
     102: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     108: aastore
     109: aload_3
     110: bipush        6
     112: bipush        77
     114: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     117: sipush        1000
     120: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     123: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     126: aastore
     127: aload_3
     128: invokestatic  #35                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     131: putfield      #39                 // Field values:Ljava/util/Map;
     134: aload_0
     135: iconst_3
     136: anewarray     #12                 // class kotlin/Pair
     139: astore_3
     140: aload_3
     141: iconst_0
     142: bipush        73
     144: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     147: iconst_2
     148: anewarray     #14                 // class java/lang/Character
     151: astore        4
     153: aload         4
     155: iconst_0
     156: bipush        86
     158: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     161: aastore
     162: aload         4
     164: iconst_1
     165: bipush        88
     167: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     170: aastore
     171: aload         4
     173: invokestatic  #45                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     176: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     179: aastore
     180: aload_3
     181: iconst_1
     182: bipush        88
     184: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     187: iconst_2
     188: anewarray     #14                 // class java/lang/Character
     191: astore        4
     193: aload         4
     195: iconst_0
     196: bipush        76
     198: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     201: aastore
     202: aload         4
     204: iconst_1
     205: bipush        67
     207: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     210: aastore
     211: aload         4
     213: invokestatic  #45                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     216: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     219: aastore
     220: aload_3
     221: iconst_2
     222: bipush        67
     224: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     227: iconst_2
     228: anewarray     #14                 // class java/lang/Character
     231: astore        4
     233: aload         4
     235: iconst_0
     236: bipush        68
     238: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     241: aastore
     242: aload         4
     244: iconst_1
     245: bipush        77
     247: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     250: aastore
     251: aload         4
     253: invokestatic  #45                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     256: invokestatic  #29                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     259: aastore
     260: aload_3
     261: invokestatic  #35                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     264: putfield      #48                 // Field prefix:Ljava/util/Map;
     267: return

  public int romanToInt(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #59                 // String s
       3: invokestatic  #65                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #71                 // Method java/lang/String.length:()I
      10: iconst_1
      11: isub
      12: istore_2
      13: iconst_0
      14: istore_3
      15: iconst_0
      16: istore        4
      18: iload         4
      20: iload_2
      21: if_icmpgt     191
      24: aload_1
      25: iload         4
      27: invokevirtual #75                 // Method java/lang/String.charAt:(I)C
      30: istore        5
      32: iload_3
      33: iload         5
      35: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      38: astore        6
      40: aload_0
      41: getfield      #48                 // Field prefix:Ljava/util/Map;
      44: aload         6
      46: invokeinterface #81,  2           // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      51: ifeq          159
      54: iload         4
      56: iload_2
      57: if_icmpge     159
      60: aload_0
      61: getfield      #48                 // Field prefix:Ljava/util/Map;
      64: iload         5
      66: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      69: invokeinterface #85,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      74: dup
      75: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      78: checkcast     #91                 // class java/util/Set
      81: aload_1
      82: iload         4
      84: iconst_1
      85: iadd
      86: invokevirtual #75                 // Method java/lang/String.charAt:(I)C
      89: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      92: invokeinterface #94,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      97: ifeq          159
     100: aload_0
     101: getfield      #39                 // Field values:Ljava/util/Map;
     104: aload_1
     105: iinc          4, 1
     108: iload         4
     110: invokevirtual #75                 // Method java/lang/String.charAt:(I)C
     113: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     116: invokeinterface #85,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     121: dup
     122: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     125: checkcast     #96                 // class java/lang/Number
     128: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     131: aload_0
     132: getfield      #39                 // Field values:Ljava/util/Map;
     135: iload         5
     137: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     140: invokeinterface #85,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     145: dup
     146: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     149: checkcast     #96                 // class java/lang/Number
     152: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     155: isub
     156: goto          183
     159: aload_0
     160: getfield      #39                 // Field values:Ljava/util/Map;
     163: iload         5
     165: invokestatic  #18                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     168: invokeinterface #85,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     173: dup
     174: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     177: checkcast     #96                 // class java/lang/Number
     180: invokevirtual #99                 // Method java/lang/Number.intValue:()I
     183: iadd
     184: istore_3
     185: iinc          4, 1
     188: goto          18
     191: iload_3
     192: ireturn
}

Compiled from "RomanToIntegerK.kt"
public interface name.valery1707.problem.leet.code.RomanToIntegerK {
  public abstract int romanToInt(java.lang.String);
}

Compiled from "RomanToIntegerK.kt"
final class name.valery1707.problem.leet.code.RomanToIntegerK$Implementation$switch extends name.valery1707.problem.leet.code.RomanToIntegerK$Implementation {
  name.valery1707.problem.leet.code.RomanToIntegerK$Implementation$switch();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: aconst_null
       4: invokespecial #10                 // Method name/valery1707/problem/leet/code/RomanToIntegerK$Implementation."<init>":(Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
       7: return

  public int romanToInt(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #21                 // String s
       3: invokestatic  #27                 // 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: aload_1
      11: invokevirtual #33                 // Method java/lang/String.length:()I
      14: iconst_1
      15: isub
      16: istore        4
      18: iconst_m1
      19: iload         4
      21: if_icmpge     160
      24: aload_1
      25: iload         4
      27: invokevirtual #37                 // Method java/lang/String.charAt:(I)C
      30: lookupswitch  { // 7
                    67: 114
                    68: 119
                    73: 96
                    76: 109
                    77: 125
                    86: 100
                    88: 104
               default: 131
          }
      96: iconst_1
      97: goto          132
     100: iconst_5
     101: goto          132
     104: bipush        10
     106: goto          132
     109: bipush        50
     111: goto          132
     114: bipush        100
     116: goto          132
     119: sipush        500
     122: goto          132
     125: sipush        1000
     128: goto          132
     131: iconst_0
     132: istore        5
     134: iload_2
     135: iload         5
     137: iload_3
     138: if_icmplt     146
     141: iload         5
     143: goto          149
     146: iload         5
     148: ineg
     149: iadd
     150: istore_2
     151: iload         5
     153: istore_3
     154: iinc          4, -1
     157: goto          18
     160: iload_2
     161: ireturn
}


package lesson3

/**
 * A small frog wants to get to the other side of the road.
 *
 * The frog is currently located at position X and wants to get to a position greater than or equal to Y.
 *
 * The small frog always jumps a fixed distance, D.
 *
 * Count the minimal number of jumps that the small frog must perform to reach its target.
 *
 * Write a function:
 *
 *     fun solution(X: Int, Y: Int, D: Int): Int
 *
 * that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y.
 *
 * For example, given:
 * ```
 *   X = 10
 *   Y = 85
 *   D = 30
 * ```
 * the function should return 3, because the frog will be positioned as follows:
 * ```
 * after the first jump, at position 10 + 30 = 40
 * after the second jump, at position 10 + 30 + 30 = 70
 * after the third jump, at position 10 + 30 + 30 + 30 = 100
 * ```
 * Write an efficient algorithm for the following assumptions:
 *
 * - X, Y and D are integers within the range [1..1,000,000,000];
 * - X ≤ Y.
 */
class FrogJmp {

    fun solution(x: Int, y: Int, d: Int): Int {
        val distance = y - x
        val jumps = distance / d

        // If the jumps are 1.1, that means 2 jumps.
        return if (distance % d == 0) jumps else jumps + 1
    }
}

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

  public final int solution(int, int, int);
    Code:
       0: iload_2
       1: iload_1
       2: isub
       3: istore        4
       5: iload         4
       7: iload_3
       8: idiv
       9: istore        5
      11: iload         4
      13: iload_3
      14: irem
      15: ifne          23
      18: iload         5
      20: goto          27
      23: iload         5
      25: iconst_1
      26: iadd
      27: ireturn
}


package lesson3

/**
 * An array A consisting of N different integers is given.
 *
 * The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing.
 *
 * Your goal is to find that missing element.
 *
 * Write a function:
 *
 *     fun solution(A: IntArray): Int
 *
 * that, given an array A, returns the value of the missing element.
 *
 * For example, given array A such that:
 * ```
 *   A[0] = 2
 *   A[1] = 3
 *   A[2] = 1
 *   A[3] = 5
 * ```
 * the function should return 4, as it is the missing element.
 *
 * Write an efficient algorithm for the following assumptions:
 *
 * - N is an integer within the range [0..100,000];
 * - the elements of A are all distinct;
 * - each element of array A is an integer within the range [1..(N + 1)].
 */
class PermMissingElem {

    fun solution(a: IntArray): Int {
        // First edge case: missing is the first nr
        if (a.isEmpty()) return 1

        a.sort()

        for (i in a.indices) {
            // Index 0 must be 1, Index 1 must be 2, and so on.
            // Whenever that's not true, we found our missing nr
            if (a[i] != i + 1) return i + 1
        }

        // Second edge case: missing is the last nr
        return a.size + 1
    }
}

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

  public final int solution(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: arraylength
       8: ifne          15
      11: iconst_1
      12: goto          16
      15: iconst_0
      16: ifeq          21
      19: iconst_1
      20: ireturn
      21: aload_1
      22: invokestatic  #27                 // Method kotlin/collections/ArraysKt.sort:([I)V
      25: iconst_0
      26: istore_2
      27: aload_1
      28: arraylength
      29: istore_3
      30: iload_2
      31: iload_3
      32: if_icmpge     54
      35: aload_1
      36: iload_2
      37: iaload
      38: iload_2
      39: iconst_1
      40: iadd
      41: if_icmpeq     48
      44: iload_2
      45: iconst_1
      46: iadd
      47: ireturn
      48: iinc          2, 1
      51: goto          30
      54: aload_1
      55: arraylength
      56: iconst_1
      57: iadd
      58: ireturn
}


package lesson2

/**
 * An array A consisting of N integers is given.
 *
 * Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place.
 *
 * For example, the rotation of array A = [[3, 8, 9, 7, 6]] is [[6, 3, 8, 9, 7]] (elements are shifted right by one index and 6 is moved to the first place).
 *
 * The goal is to rotate array A K times; that is, each element of A will be shifted to the right K times.
 * Write a function:
 *
 *    fun solution(A: IntArray, K: Int): IntArray
 *
 * that, given an array A consisting of N integers and an integer K, returns the array A rotated K times.
 *
 * For example, given:
 *     A = [[3, 8, 9, 7, 6]]
 *     K = 3
 * the function should return [9, 7, 6, 3, 8].
 *
 * Three rotations were made:
 * ```
 *    [3, 8, 9, 7, 6] -> [6, 3, 8, 9, 7]
 *    [6, 3, 8, 9, 7] -> [7, 6, 3, 8, 9]
 *    [7, 6, 3, 8, 9] -> [9, 7, 6, 3, 8]
 * ```
 *
 * For another example, given:
 *     A = [[0, 0, 0]]
 *     K = 1
 * the function should return [[0, 0, 0]]
 *
 * Given:
 *     A = [[1, 2, 3, 4]]
 *     K = 4
 * the function should return [[1, 2, 3, 4]]
 *
 * Assume that:
 * - N and K are integers within the range [[0..100]];
 * - each element of array A is an integer within the range [[−1,000..1,000]].
 *
 * In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.
 */
class CyclicRotation {

    fun solution(a: IntArray, k: Int): IntArray {
        // If no rotation or rotation leaves the array as is, return immediately
        if (k == 0 || a.isEmpty() || k % a.size == 0) return a

        // Reduce to the minimum amount of rotations needed
        val minK = k - (a.size * (k / a.size))

        val initialArray = a.toCollection(ArrayDeque())

        for (i in 1..minK) initialArray.addFirst(initialArray.removeLast())

        return initialArray.toIntArray()
    }
}

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

  public final int[] solution(int[], int);
    Code:
       0: aload_1
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_2
       7: ifeq          30
      10: aload_1
      11: arraylength
      12: ifne          19
      15: iconst_1
      16: goto          20
      19: iconst_0
      20: ifne          30
      23: iload_2
      24: aload_1
      25: arraylength
      26: irem
      27: ifne          32
      30: aload_1
      31: areturn
      32: iload_2
      33: aload_1
      34: arraylength
      35: iload_2
      36: aload_1
      37: arraylength
      38: idiv
      39: imul
      40: isub
      41: istore_3
      42: aload_1
      43: new           #23                 // class kotlin/collections/ArrayDeque
      46: dup
      47: invokespecial #24                 // Method kotlin/collections/ArrayDeque."<init>":()V
      50: checkcast     #26                 // class java/util/Collection
      53: invokestatic  #32                 // Method kotlin/collections/ArraysKt.toCollection:([ILjava/util/Collection;)Ljava/util/Collection;
      56: checkcast     #23                 // class kotlin/collections/ArrayDeque
      59: astore        4
      61: iconst_1
      62: istore        5
      64: iload         5
      66: iload_3
      67: if_icmpgt     92
      70: aload         4
      72: aload         4
      74: invokevirtual #36                 // Method kotlin/collections/ArrayDeque.removeLast:()Ljava/lang/Object;
      77: invokevirtual #40                 // Method kotlin/collections/ArrayDeque.addFirst:(Ljava/lang/Object;)V
      80: iload         5
      82: iload_3
      83: if_icmpeq     92
      86: iinc          5, 1
      89: goto          70
      92: aload         4
      94: checkcast     #26                 // class java/util/Collection
      97: invokestatic  #46                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     100: areturn
}


package lesson2

/**
 * A non-empty array A consisting of N integers is given.
 * The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired.
 *
 * For example, in array A such that:
 * ```
 *   A[0] = 9  A[1] = 3  A[2] = 9
 *   A[3] = 3  A[4] = 9  A[5] = 7
 *   A[6] = 9
 * ```
 * the elements at indexes 0 and 2 have value 9,
 * the elements at indexes 1 and 3 have value 3,
 * the elements at indexes 4 and 6 have value 9,
 * the element at index 5 has value 7 and is unpaired.
 *
 * Write a function:
 *
 *     fun solution(A: IntArray): Int
 *
 * that, given an array A consisting of N integers fulfilling the above conditions, returns the value of the unpaired element.
 *
 * For example, given array A such that:
 * ```
 *   A[0] = 9  A[1] = 3  A[2] = 9
 *   A[3] = 3  A[4] = 9  A[5] = 7
 *   A[6] = 9
 * ```
 * the function should return 7, as explained in the example above.
 *
 * Write an efficient algorithm for the following assumptions:
 * - N is an odd integer within the range [1..1,000,000];
 * - each element of array A is an integer within the range [1..1,000,000,000];
 * - all but one of the values in A occur an even number of times.
 */
class OddOccurrencesInArray {

    fun solution(a: IntArray): Int {
        var unpairedElement = 0

        for (element in a) unpairedElement = unpairedElement xor element

        return unpairedElement
    }
}

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

  public final int solution(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String a
       3: invokestatic  #21                 // 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: aload_1
      11: arraylength
      12: istore        4
      14: iload_3
      15: iload         4
      17: if_icmpge     36
      20: aload_1
      21: iload_3
      22: iaload
      23: istore        5
      25: iload_2
      26: iload         5
      28: ixor
      29: istore_2
      30: iinc          3, 1
      33: goto          14
      36: iload_2
      37: ireturn
}


package lesson1

/**
 * A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
 *
 * For example:
 * - The number 9 has binary representation 1001 and contains a binary gap of length 2.
 * - The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3.
 * - The number 20 has binary representation 10100 and contains one binary gap of length 1.
 * - The number 15 has binary representation 1111 and has no binary gaps.
 * - The number 32 has binary representation 100000 and has no binary gaps.
 *
 * Write a function:
 *
 *     class Solution { public int solution(int N); }
 *
 * that, given a positive integer N, returns the length of its longest binary gap.
 * The function should return 0 if N doesn't contain a binary gap.
 *
 * For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5.
 * Given N = 32 the function should return 0, because N has binary representation '100000' and thus no binary gaps.
 *
 * Write an efficient algorithm for the following assumptions:
 *
 * N is an integer within the range [1..2,147,483,647].
 */
class BinaryGap {

    fun solution(n: Int): Int {
        var longestBinaryGap = 0
        var currentBinaryGap = 0
        var isCounting = false

        // Get binary representation
        val binaryString = Integer.toBinaryString(n)

        for (char in binaryString) {
            when {
                // If we were already counting means binary gap ended
                char == '1' && isCounting -> {
                    if (currentBinaryGap > longestBinaryGap) {
                        longestBinaryGap = currentBinaryGap
                    }
                    currentBinaryGap = 0
                }

                // When finding a 1 start counting
                char == '1' -> isCounting = true

                // When counting -> increment our binary gap
                char == '0' && isCounting -> currentBinaryGap++
            }
        }

        return longestBinaryGap
    }

}

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

  public final int solution(int);
    Code:
       0: iconst_0
       1: istore_2
       2: iconst_0
       3: istore_3
       4: iconst_0
       5: istore        4
       7: iload_1
       8: invokestatic  #18                 // Method java/lang/Integer.toBinaryString:(I)Ljava/lang/String;
      11: astore        5
      13: aload         5
      15: invokestatic  #24                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      18: aload         5
      20: astore        6
      22: iconst_0
      23: istore        7
      25: aload         6
      27: invokevirtual #30                 // Method java/lang/String.length:()I
      30: istore        8
      32: iload         7
      34: iload         8
      36: if_icmpge     107
      39: aload         6
      41: iload         7
      43: invokevirtual #34                 // Method java/lang/String.charAt:(I)C
      46: istore        9
      48: nop
      49: iload         9
      51: bipush        49
      53: if_icmpne     73
      56: iload         4
      58: ifeq          73
      61: iload_3
      62: iload_2
      63: if_icmple     68
      66: iload_3
      67: istore_2
      68: iconst_0
      69: istore_3
      70: goto          101
      73: iload         9
      75: bipush        49
      77: if_icmpne     86
      80: iconst_1
      81: istore        4
      83: goto          101
      86: iload         9
      88: bipush        48
      90: if_icmpne     101
      93: iload         4
      95: ifeq          101
      98: iinc          3, 1
     101: iinc          7, 1
     104: goto          32
     107: iload_2
     108: ireturn
}


package d09

import java.io.File
import kotlin.math.pow
import kotlin.math.sqrt

fun main() {

    fun dist(p1: Pair<Int, Int>, p2: Pair<Int, Int>) = sqrt(
        (p1.first - p2.first).toDouble().pow(2) +
                (p1.second - p2.second).toDouble().pow(2)
    )

    fun part1(input: List<String>) {
        var h = Pair(0, 0)
        var t = Pair(0, 0)
        var prev = Pair(0, 0)
        val visited = mutableSetOf<Pair<Int, Int>>()
        visited.add(prev)

        input.forEach {
            val (d, m) = it.split(' ')

            // dist, mag
            repeat(m.toInt()) {
                prev = h

                h = when (d) {
                    "U" -> h.copy(second = h.second + 1)
                    "D" -> h.copy(second = h.second - 1)
                    "L" -> h.copy(first = h.first - 1)
                    else -> h.copy(first = h.first + 1)
                }

                if (dist(h, t) > sqrt(2.0)) {
                    t = prev.copy()
                    visited.add(t)
                }
            }
        }

        println(visited.size)
    }

    fun part2(input: List<String>) {
        val p = MutableList(10) { Pair(0, 0) }
        var prev = Pair(0, 0)
        val visited = mutableSetOf<Pair<Int, Int>>()
        visited.add(prev)

        input.forEach { line ->
            val (d, m) = line.split(' ')

            repeat(m.toInt()) {
                prev = p[0]

                p[0] = when (d) {
                    "U" -> p[0].copy(second = p[0].second + 1)
                    "D" -> p[0].copy(second = p[0].second - 1)
                    "L" -> p[0].copy(first = p[0].first - 1)
                    else -> p[0].copy(first = p[0].first + 1)
                }

                for (i in 0 until p.size - 1) {
                    if (dist(p[i], p[i + 1]) > sqrt(2.0)) {
                        val dx = prev.first - p[1].first
                        val dy = prev.second - p[1].second

                        val indices = mutableSetOf(1)

                        for (j in i + 1 until p.size - 1) {
                            if (dist(p[j], p[j + 1]) != 1.0) {
                                break
                            }
                            indices.add(j + 1)
                        }

                        indices.forEach { p[it] = p[it].copy(p[it].first + dx, p[it].second + dy) }
                        visited.add(p.last())
                    }
                }
            }
        }

        println(visited.size)
    }

    val input = File("src/d09/input").readLines()

    part1(input)
    part2(input)
}

Compiled from "Main.kt"
public final class d09.MainKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/d09/input
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: invokestatic  #24                 // Method main$part1:(Ljava/util/List;)V
      20: aload_0
      21: invokestatic  #27                 // Method main$part2:(Ljava/util/List;)V
      24: return

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

  private static final double main$dist(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: nop
       1: aload_0
       2: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #45                 // class java/lang/Number
       8: invokevirtual #49                 // Method java/lang/Number.intValue:()I
      11: aload_1
      12: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      15: checkcast     #45                 // class java/lang/Number
      18: invokevirtual #49                 // Method java/lang/Number.intValue:()I
      21: isub
      22: i2d
      23: iconst_2
      24: i2d
      25: invokestatic  #55                 // Method java/lang/Math.pow:(DD)D
      28: aload_0
      29: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      32: checkcast     #45                 // class java/lang/Number
      35: invokevirtual #49                 // Method java/lang/Number.intValue:()I
      38: aload_1
      39: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      42: checkcast     #45                 // class java/lang/Number
      45: invokevirtual #49                 // Method java/lang/Number.intValue:()I
      48: isub
      49: i2d
      50: iconst_2
      51: i2d
      52: invokestatic  #55                 // Method java/lang/Math.pow:(DD)D
      55: dadd
      56: invokestatic  #62                 // Method java/lang/Math.sqrt:(D)D
      59: dreturn

  private static final void main$part1(java.util.List<java.lang.String>);
    Code:
       0: aconst_null
       1: astore_1
       2: new           #39                 // class kotlin/Pair
       5: dup
       6: iconst_0
       7: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      10: iconst_0
      11: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      17: astore_1
      18: aconst_null
      19: astore_2
      20: new           #39                 // class kotlin/Pair
      23: dup
      24: iconst_0
      25: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: iconst_0
      29: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      35: astore_2
      36: aconst_null
      37: astore_3
      38: new           #39                 // class kotlin/Pair
      41: dup
      42: iconst_0
      43: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: iconst_0
      47: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      50: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      53: astore_3
      54: new           #77                 // class java/util/LinkedHashSet
      57: dup
      58: invokespecial #79                 // Method java/util/LinkedHashSet."<init>":()V
      61: checkcast     #81                 // class java/util/Set
      64: astore        4
      66: aload         4
      68: aload_3
      69: invokeinterface #85,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      74: pop
      75: aload_0
      76: checkcast     #87                 // class java/lang/Iterable
      79: astore        5
      81: iconst_0
      82: istore        6
      84: aload         5
      86: invokeinterface #91,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      91: astore        7
      93: aload         7
      95: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     100: ifeq          426
     103: aload         7
     105: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     110: astore        8
     112: aload         8
     114: checkcast     #102                // class java/lang/String
     117: astore        9
     119: iconst_0
     120: istore        10
     122: aload         9
     124: checkcast     #104                // class java/lang/CharSequence
     127: iconst_1
     128: newarray       char
     130: astore        11
     132: aload         11
     134: iconst_0
     135: bipush        32
     137: castore
     138: aload         11
     140: iconst_0
     141: iconst_0
     142: bipush        6
     144: aconst_null
     145: invokestatic  #110                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     148: astore        12
     150: aload         12
     152: iconst_0
     153: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     158: checkcast     #102                // class java/lang/String
     161: astore        11
     163: aload         12
     165: iconst_1
     166: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     171: checkcast     #102                // class java/lang/String
     174: astore        13
     176: aload         13
     178: invokestatic  #120                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     181: istore        14
     183: iconst_0
     184: istore        15
     186: iload         15
     188: iload         14
     190: if_icmpge     421
     193: iload         15
     195: istore        16
     197: iconst_0
     198: istore        17
     200: aload_1
     201: astore_3
     202: aload         11
     204: astore        18
     206: aload         18
     208: invokevirtual #123                // Method java/lang/String.hashCode:()I
     211: lookupswitch  { // 3
                    68: 244
                    76: 270
                    85: 257
               default: 358
          }
     244: aload         18
     246: ldc           #125                // String D
     248: invokevirtual #128                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     251: ifne          308
     254: goto          358
     257: aload         18
     259: ldc           #130                // String U
     261: invokevirtual #128                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     264: ifne          283
     267: goto          358
     270: aload         18
     272: ldc           #132                // String L
     274: invokevirtual #128                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     277: ifne          333
     280: goto          358
     283: aload_1
     284: aconst_null
     285: aload_1
     286: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     289: checkcast     #45                 // class java/lang/Number
     292: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     295: iconst_1
     296: iadd
     297: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     300: iconst_1
     301: aconst_null
     302: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     305: goto          380
     308: aload_1
     309: aconst_null
     310: aload_1
     311: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     314: checkcast     #45                 // class java/lang/Number
     317: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     320: iconst_1
     321: isub
     322: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     325: iconst_1
     326: aconst_null
     327: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     330: goto          380
     333: aload_1
     334: aload_1
     335: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     338: checkcast     #45                 // class java/lang/Number
     341: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     344: iconst_1
     345: isub
     346: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     349: aconst_null
     350: iconst_2
     351: aconst_null
     352: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     355: goto          380
     358: aload_1
     359: aload_1
     360: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     363: checkcast     #45                 // class java/lang/Number
     366: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     369: iconst_1
     370: iadd
     371: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     374: aconst_null
     375: iconst_2
     376: aconst_null
     377: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     380: astore_1
     381: aload_1
     382: aload_2
     383: invokestatic  #138                // Method main$dist:(Lkotlin/Pair;Lkotlin/Pair;)D
     386: ldc2_w        #139                // double 2.0d
     389: invokestatic  #62                 // Method java/lang/Math.sqrt:(D)D
     392: dcmpl
     393: ifle          414
     396: aload_3
     397: aconst_null
     398: aconst_null
     399: iconst_3
     400: aconst_null
     401: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     404: astore_2
     405: aload         4
     407: aload_2
     408: invokeinterface #85,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     413: pop
     414: nop
     415: iinc          15, 1
     418: goto          186
     421: nop
     422: nop
     423: goto          93
     426: nop
     427: aload         4
     429: invokeinterface #143,  1          // InterfaceMethod java/util/Set.size:()I
     434: istore        5
     436: getstatic     #149                // Field java/lang/System.out:Ljava/io/PrintStream;
     439: iload         5
     441: invokevirtual #155                // Method java/io/PrintStream.println:(I)V
     444: return

  private static final void main$part2(java.util.List<java.lang.String>);
    Code:
       0: bipush        10
       2: istore_2
       3: new           #174                // class java/util/ArrayList
       6: dup
       7: iload_2
       8: invokespecial #176                // Method java/util/ArrayList."<init>":(I)V
      11: astore_3
      12: iconst_0
      13: istore        4
      15: iload         4
      17: iload_2
      18: if_icmpge     63
      21: iload         4
      23: istore        5
      25: aload_3
      26: iload         5
      28: istore        6
      30: astore        28
      32: iconst_0
      33: istore        7
      35: new           #39                 // class kotlin/Pair
      38: dup
      39: iconst_0
      40: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      43: iconst_0
      44: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      50: aload         28
      52: swap
      53: invokevirtual #177                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      56: pop
      57: iinc          4, 1
      60: goto          15
      63: aload_3
      64: checkcast     #112                // class java/util/List
      67: astore_1
      68: aconst_null
      69: astore_2
      70: new           #39                 // class kotlin/Pair
      73: dup
      74: iconst_0
      75: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: iconst_0
      79: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      82: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      85: astore_2
      86: new           #77                 // class java/util/LinkedHashSet
      89: dup
      90: invokespecial #79                 // Method java/util/LinkedHashSet."<init>":()V
      93: checkcast     #81                 // class java/util/Set
      96: astore_3
      97: aload_3
      98: aload_2
      99: invokeinterface #85,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     104: pop
     105: aload_0
     106: checkcast     #87                 // class java/lang/Iterable
     109: astore        4
     111: iconst_0
     112: istore        5
     114: aload         4
     116: invokeinterface #91,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     121: astore        6
     123: aload         6
     125: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     130: ifeq          893
     133: aload         6
     135: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     140: astore        7
     142: aload         7
     144: checkcast     #102                // class java/lang/String
     147: astore        8
     149: iconst_0
     150: istore        9
     152: aload         8
     154: checkcast     #104                // class java/lang/CharSequence
     157: iconst_1
     158: newarray       char
     160: astore        10
     162: aload         10
     164: iconst_0
     165: bipush        32
     167: castore
     168: aload         10
     170: iconst_0
     171: iconst_0
     172: bipush        6
     174: aconst_null
     175: invokestatic  #110                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     178: astore        11
     180: aload         11
     182: iconst_0
     183: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     188: checkcast     #102                // class java/lang/String
     191: astore        10
     193: aload         11
     195: iconst_1
     196: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     201: checkcast     #102                // class java/lang/String
     204: astore        12
     206: aload         12
     208: invokestatic  #120                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     211: istore        13
     213: iconst_0
     214: istore        14
     216: iload         14
     218: iload         13
     220: if_icmpge     888
     223: iload         14
     225: istore        15
     227: iconst_0
     228: istore        16
     230: aload_1
     231: iconst_0
     232: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     237: astore_2
     238: aload_1
     239: iconst_0
     240: aload         10
     242: astore        17
     244: aload         17
     246: invokevirtual #123                // Method java/lang/String.hashCode:()I
     249: lookupswitch  { // 3
                    68: 284
                    76: 310
                    85: 297
               default: 452
          }
     284: aload         17
     286: ldc           #125                // String D
     288: invokevirtual #128                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     291: ifne          366
     294: goto          452
     297: aload         17
     299: ldc           #130                // String U
     301: invokevirtual #128                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     304: ifne          323
     307: goto          452
     310: aload         17
     312: ldc           #132                // String L
     314: invokevirtual #128                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     317: ifne          409
     320: goto          452
     323: aload_1
     324: iconst_0
     325: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     330: checkcast     #39                 // class kotlin/Pair
     333: aconst_null
     334: aload_1
     335: iconst_0
     336: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     341: checkcast     #39                 // class kotlin/Pair
     344: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     347: checkcast     #45                 // class java/lang/Number
     350: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     353: iconst_1
     354: iadd
     355: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     358: iconst_1
     359: aconst_null
     360: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     363: goto          492
     366: aload_1
     367: iconst_0
     368: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     373: checkcast     #39                 // class kotlin/Pair
     376: aconst_null
     377: aload_1
     378: iconst_0
     379: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     384: checkcast     #39                 // class kotlin/Pair
     387: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     390: checkcast     #45                 // class java/lang/Number
     393: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     396: iconst_1
     397: isub
     398: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     401: iconst_1
     402: aconst_null
     403: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     406: goto          492
     409: aload_1
     410: iconst_0
     411: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     416: checkcast     #39                 // class kotlin/Pair
     419: aload_1
     420: iconst_0
     421: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     426: checkcast     #39                 // class kotlin/Pair
     429: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     432: checkcast     #45                 // class java/lang/Number
     435: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     438: iconst_1
     439: isub
     440: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     443: aconst_null
     444: iconst_2
     445: aconst_null
     446: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     449: goto          492
     452: aload_1
     453: iconst_0
     454: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     459: checkcast     #39                 // class kotlin/Pair
     462: aload_1
     463: iconst_0
     464: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     469: checkcast     #39                 // class kotlin/Pair
     472: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     475: checkcast     #45                 // class java/lang/Number
     478: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     481: iconst_1
     482: iadd
     483: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     486: aconst_null
     487: iconst_2
     488: aconst_null
     489: invokestatic  #136                // Method kotlin/Pair.copy$default:(Lkotlin/Pair;Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;)Lkotlin/Pair;
     492: invokeinterface #181,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     497: pop
     498: iconst_0
     499: istore        17
     501: aload_1
     502: invokeinterface #182,  1          // InterfaceMethod java/util/List.size:()I
     507: iconst_1
     508: isub
     509: istore        18
     511: iload         17
     513: iload         18
     515: if_icmpge     881
     518: aload_1
     519: iload         17
     521: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     526: checkcast     #39                 // class kotlin/Pair
     529: aload_1
     530: iload         17
     532: iconst_1
     533: iadd
     534: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     539: checkcast     #39                 // class kotlin/Pair
     542: invokestatic  #138                // Method main$dist:(Lkotlin/Pair;Lkotlin/Pair;)D
     545: ldc2_w        #139                // double 2.0d
     548: invokestatic  #62                 // Method java/lang/Math.sqrt:(D)D
     551: dcmpl
     552: ifle          875
     555: aload_2
     556: checkcast     #39                 // class kotlin/Pair
     559: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     562: checkcast     #45                 // class java/lang/Number
     565: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     568: aload_1
     569: iconst_1
     570: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     575: checkcast     #39                 // class kotlin/Pair
     578: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     581: checkcast     #45                 // class java/lang/Number
     584: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     587: isub
     588: istore        19
     590: aload_2
     591: checkcast     #39                 // class kotlin/Pair
     594: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     597: checkcast     #45                 // class java/lang/Number
     600: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     603: aload_1
     604: iconst_1
     605: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     610: checkcast     #39                 // class kotlin/Pair
     613: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     616: checkcast     #45                 // class java/lang/Number
     619: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     622: isub
     623: istore        20
     625: iconst_1
     626: anewarray     #68                 // class java/lang/Integer
     629: astore        21
     631: aload         21
     633: iconst_0
     634: iconst_1
     635: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     638: aastore
     639: aload         21
     641: invokestatic  #188                // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
     644: astore        22
     646: iload         17
     648: iconst_1
     649: iadd
     650: istore        21
     652: aload_1
     653: invokeinterface #182,  1          // InterfaceMethod java/util/List.size:()I
     658: iconst_1
     659: isub
     660: istore        23
     662: iload         21
     664: iload         23
     666: if_icmpge     733
     669: aload_1
     670: iload         21
     672: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     677: checkcast     #39                 // class kotlin/Pair
     680: aload_1
     681: iload         21
     683: iconst_1
     684: iadd
     685: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     690: checkcast     #39                 // class kotlin/Pair
     693: invokestatic  #138                // Method main$dist:(Lkotlin/Pair;Lkotlin/Pair;)D
     696: dconst_1
     697: dcmpg
     698: ifne          705
     701: iconst_1
     702: goto          706
     705: iconst_0
     706: ifne          712
     709: goto          733
     712: aload         22
     714: iload         21
     716: iconst_1
     717: iadd
     718: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     721: invokeinterface #85,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     726: pop
     727: iinc          21, 1
     730: goto          662
     733: aload         22
     735: checkcast     #87                 // class java/lang/Iterable
     738: astore        21
     740: iconst_0
     741: istore        23
     743: aload         21
     745: invokeinterface #91,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     750: astore        24
     752: aload         24
     754: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     759: ifeq          863
     762: aload         24
     764: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     769: astore        25
     771: aload         25
     773: checkcast     #45                 // class java/lang/Number
     776: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     779: istore        26
     781: iconst_0
     782: istore        27
     784: aload_1
     785: iload         26
     787: aload_1
     788: iload         26
     790: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     795: checkcast     #39                 // class kotlin/Pair
     798: aload_1
     799: iload         26
     801: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     806: checkcast     #39                 // class kotlin/Pair
     809: invokevirtual #43                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     812: checkcast     #45                 // class java/lang/Number
     815: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     818: iload         19
     820: iadd
     821: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     824: aload_1
     825: iload         26
     827: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     832: checkcast     #39                 // class kotlin/Pair
     835: invokevirtual #58                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     838: checkcast     #45                 // class java/lang/Number
     841: invokevirtual #49                 // Method java/lang/Number.intValue:()I
     844: iload         20
     846: iadd
     847: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     850: invokevirtual #192                // Method kotlin/Pair.copy:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     853: invokeinterface #181,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     858: pop
     859: nop
     860: goto          752
     863: nop
     864: aload_3
     865: aload_1
     866: invokestatic  #198                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     869: invokeinterface #85,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     874: pop
     875: iinc          17, 1
     878: goto          511
     881: nop
     882: iinc          14, 1
     885: goto          216
     888: nop
     889: nop
     890: goto          123
     893: nop
     894: aload_3
     895: invokeinterface #143,  1          // InterfaceMethod java/util/Set.size:()I
     900: istore        4
     902: getstatic     #149                // Field java/lang/System.out:Ljava/io/PrintStream;
     905: iload         4
     907: invokevirtual #155                // Method java/io/PrintStream.println:(I)V
     910: return
}


package d07

import java.io.File

fun main() {
    data class Trie(
        val dir: String,
        val children: MutableMap<String, Trie> = mutableMapOf(),
        val parent: Trie? = null,
        var dirSize: Long = 0L
    )

    // combining parts for this day
    val input = File("src/d07/input").readLines()

    val root = Trie("/")
    var curr = root

    input.drop(1).forEach {
        if (it.startsWith("$ cd")) {
            val dir = it.split(' ')[2]
            curr = if (dir == "..") curr.parent!! else curr.children[dir]!!
        } else if (it.startsWith("dir")) {
            val dir = it.split(' ')[1]
            curr.children[dir] = Trie(dir = "${curr.dir}/$dir", parent = curr)
        } else if (!it.startsWith("$ ls")) {
            curr.dirSize += it.split(' ')[0].toLong()
        }
    }

    val sizes = mutableMapOf<String, Long>()

    fun traverse(root: Trie): Long {
        val tmp = root.dirSize + root.children.values.sumOf { traverse(it) }
        sizes[root.dir] = tmp
        return tmp
    }

    traverse(root)

    println(sizes.values.sumOf { if (it <= 100000) it else 0 }) // part 1
    val total = sizes["/"]!!
    println(sizes.values.filter { 70000000 - total + it >= 30000000 }.min()) // part 2
}

Compiled from "Main.kt"
public final class d07.MainKt$main$Trie {
  private final java.lang.String dir;

  private final java.util.Map<java.lang.String, d07.MainKt$main$Trie> children;

  private final d07.MainKt$main$Trie parent;

  private long dirSize;

  public d07.MainKt$main$Trie(java.lang.String, java.util.Map<java.lang.String, d07.MainKt$main$Trie>, d07.MainKt$main$Trie, long);
    Code:
       0: aload_1
       1: ldc           #9                  // String dir
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #17                 // String children
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #20                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #23                 // Field dir:Ljava/lang/String;
      21: aload_0
      22: aload_2
      23: putfield      #26                 // Field children:Ljava/util/Map;
      26: aload_0
      27: aload_3
      28: putfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
      31: aload_0
      32: lload         4
      34: putfield      #34                 // Field dirSize:J
      37: return

  public d07.MainKt$main$Trie(java.lang.String, java.util.Map, d07.MainKt$main$Trie, long, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         6
       2: iconst_2
       3: iand
       4: ifeq          18
       7: new           #38                 // class java/util/LinkedHashMap
      10: dup
      11: invokespecial #39                 // Method java/util/LinkedHashMap."<init>":()V
      14: checkcast     #41                 // class java/util/Map
      17: astore_2
      18: iload         6
      20: iconst_4
      21: iand
      22: ifeq          27
      25: aconst_null
      26: astore_3
      27: iload         6
      29: bipush        8
      31: iand
      32: ifeq          38
      35: lconst_0
      36: lstore        4
      38: aload_0
      39: aload_1
      40: aload_2
      41: aload_3
      42: lload         4
      44: invokespecial #43                 // Method "<init>":(Ljava/lang/String;Ljava/util/Map;Ld07/MainKt$main$Trie;J)V
      47: return

  public final java.lang.String getDir();
    Code:
       0: aload_0
       1: getfield      #23                 // Field dir:Ljava/lang/String;
       4: areturn

  public final java.util.Map<java.lang.String, d07.MainKt$main$Trie> getChildren();
    Code:
       0: aload_0
       1: getfield      #26                 // Field children:Ljava/util/Map;
       4: areturn

  public final d07.MainKt$main$Trie getParent();
    Code:
       0: aload_0
       1: getfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
       4: areturn

  public final long getDirSize();
    Code:
       0: aload_0
       1: getfield      #34                 // Field dirSize:J
       4: lreturn

  public final void setDirSize(long);
    Code:
       0: aload_0
       1: lload_1
       2: putfield      #34                 // Field dirSize:J
       5: return

  public final java.lang.String component1();
    Code:
       0: aload_0
       1: getfield      #23                 // Field dir:Ljava/lang/String;
       4: areturn

  public final java.util.Map<java.lang.String, d07.MainKt$main$Trie> component2();
    Code:
       0: aload_0
       1: getfield      #26                 // Field children:Ljava/util/Map;
       4: areturn

  public final d07.MainKt$main$Trie component3();
    Code:
       0: aload_0
       1: getfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
       4: areturn

  public final long component4();
    Code:
       0: aload_0
       1: getfield      #34                 // Field dirSize:J
       4: lreturn

  public final d07.MainKt$main$Trie copy(java.lang.String, java.util.Map<java.lang.String, d07.MainKt$main$Trie>, d07.MainKt$main$Trie, long);
    Code:
       0: aload_1
       1: ldc           #9                  // String dir
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #17                 // String children
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class d07/MainKt$main$Trie
      15: dup
      16: aload_1
      17: aload_2
      18: aload_3
      19: lload         4
      21: invokespecial #43                 // Method "<init>":(Ljava/lang/String;Ljava/util/Map;Ld07/MainKt$main$Trie;J)V
      24: areturn

  public static d07.MainKt$main$Trie copy$default(d07.MainKt$main$Trie, java.lang.String, java.util.Map, d07.MainKt$main$Trie, long, int, java.lang.Object);
    Code:
       0: iload         6
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #23                 // Field dir:Ljava/lang/String;
      11: astore_1
      12: iload         6
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #26                 // Field children:Ljava/util/Map;
      23: astore_2
      24: iload         6
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
      35: astore_3
      36: iload         6
      38: bipush        8
      40: iand
      41: ifeq          50
      44: aload_0
      45: getfield      #34                 // Field dirSize:J
      48: lstore        4
      50: aload_0
      51: aload_1
      52: aload_2
      53: aload_3
      54: lload         4
      56: invokevirtual #66                 // Method copy:(Ljava/lang/String;Ljava/util/Map;Ld07/MainKt$main$Trie;J)Ld07/MainKt$main$Trie;
      59: areturn

  public java.lang.String toString();
    Code:
       0: new           #69                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #70                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #72                 // String Trie(dir=
       9: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #23                 // Field dir:Ljava/lang/String;
      16: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      19: ldc           #78                 // String , children=
      21: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #26                 // Field children:Ljava/util/Map;
      28: invokevirtual #81                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: ldc           #83                 // String , parent=
      33: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
      40: invokevirtual #81                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      43: ldc           #85                 // String , dirSize=
      45: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      48: aload_0
      49: getfield      #34                 // Field dirSize:J
      52: invokevirtual #88                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      55: bipush        41
      57: invokevirtual #91                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      60: invokevirtual #93                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      63: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #23                 // Field dir:Ljava/lang/String;
       4: invokevirtual #99                 // Method java/lang/String.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #26                 // Field children:Ljava/util/Map;
      16: invokevirtual #100                // Method java/lang/Object.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
      29: ifnonnull     36
      32: iconst_0
      33: goto          43
      36: aload_0
      37: getfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
      40: invokevirtual #101                // Method hashCode:()I
      43: iadd
      44: istore_1
      45: iload_1
      46: bipush        31
      48: imul
      49: aload_0
      50: getfield      #34                 // Field dirSize:J
      53: invokestatic  #106                // Method java/lang/Long.hashCode:(J)I
      56: iadd
      57: istore_1
      58: iload_1
      59: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class d07/MainKt$main$Trie
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class d07/MainKt$main$Trie
      20: astore_2
      21: aload_0
      22: getfield      #23                 // Field dir:Ljava/lang/String;
      25: aload_2
      26: getfield      #23                 // Field dir:Ljava/lang/String;
      29: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #26                 // Field children:Ljava/util/Map;
      41: aload_2
      42: getfield      #26                 // Field children:Ljava/util/Map;
      45: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: ifne          53
      51: iconst_0
      52: ireturn
      53: aload_0
      54: getfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
      57: aload_2
      58: getfield      #30                 // Field parent:Ld07/MainKt$main$Trie;
      61: invokestatic  #114                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      64: ifne          69
      67: iconst_0
      68: ireturn
      69: aload_0
      70: getfield      #34                 // Field dirSize:J
      73: aload_2
      74: getfield      #34                 // Field dirSize:J
      77: lcmp
      78: ifeq          83
      81: iconst_0
      82: ireturn
      83: iconst_1
      84: ireturn
}

Compiled from "Main.kt"
public final class d07.MainKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/d07/input
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: new           #22                 // class d07/MainKt$main$Trie
      19: dup
      20: ldc           #24                 // String /
      22: aconst_null
      23: aconst_null
      24: lconst_0
      25: bipush        14
      27: aconst_null
      28: invokespecial #27                 // Method d07/MainKt$main$Trie."<init>":(Ljava/lang/String;Ljava/util/Map;Ld07/MainKt$main$Trie;JILkotlin/jvm/internal/DefaultConstructorMarker;)V
      31: astore_1
      32: aconst_null
      33: astore_2
      34: aload_1
      35: astore_2
      36: aload_0
      37: checkcast     #29                 // class java/lang/Iterable
      40: iconst_1
      41: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      44: checkcast     #29                 // class java/lang/Iterable
      47: astore_3
      48: iconst_0
      49: istore        4
      51: aload_3
      52: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        5
      59: aload         5
      61: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          356
      69: aload         5
      71: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      76: astore        6
      78: aload         6
      80: checkcast     #51                 // class java/lang/String
      83: astore        7
      85: iconst_0
      86: istore        8
      88: aload         7
      90: ldc           #53                 // String $ cd
      92: iconst_0
      93: iconst_2
      94: aconst_null
      95: invokestatic  #59                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      98: ifeq          181
     101: aload         7
     103: checkcast     #61                 // class java/lang/CharSequence
     106: iconst_1
     107: newarray       char
     109: astore        9
     111: aload         9
     113: iconst_0
     114: bipush        32
     116: castore
     117: aload         9
     119: iconst_0
     120: iconst_0
     121: bipush        6
     123: aconst_null
     124: invokestatic  #65                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     127: iconst_2
     128: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     133: checkcast     #51                 // class java/lang/String
     136: astore        10
     138: aload         10
     140: ldc           #73                 // String ..
     142: invokestatic  #79                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     145: ifeq          159
     148: aload_2
     149: invokevirtual #83                 // Method d07/MainKt$main$Trie.getParent:()Ld07/MainKt$main$Trie;
     152: dup
     153: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     156: goto          177
     159: aload_2
     160: invokevirtual #91                 // Method d07/MainKt$main$Trie.getChildren:()Ljava/util/Map;
     163: aload         10
     165: invokeinterface #96,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     170: dup
     171: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     174: checkcast     #22                 // class d07/MainKt$main$Trie
     177: astore_2
     178: goto          351
     181: aload         7
     183: ldc           #98                 // String dir
     185: iconst_0
     186: iconst_2
     187: aconst_null
     188: invokestatic  #59                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     191: ifeq          286
     194: aload         7
     196: checkcast     #61                 // class java/lang/CharSequence
     199: iconst_1
     200: newarray       char
     202: astore        9
     204: aload         9
     206: iconst_0
     207: bipush        32
     209: castore
     210: aload         9
     212: iconst_0
     213: iconst_0
     214: bipush        6
     216: aconst_null
     217: invokestatic  #65                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     220: iconst_1
     221: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     226: checkcast     #51                 // class java/lang/String
     229: astore        10
     231: aload_2
     232: invokevirtual #91                 // Method d07/MainKt$main$Trie.getChildren:()Ljava/util/Map;
     235: aload         10
     237: new           #22                 // class d07/MainKt$main$Trie
     240: dup
     241: new           #100                // class java/lang/StringBuilder
     244: dup
     245: invokespecial #102                // Method java/lang/StringBuilder."<init>":()V
     248: aload_2
     249: invokevirtual #106                // Method d07/MainKt$main$Trie.getDir:()Ljava/lang/String;
     252: invokevirtual #110                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     255: bipush        47
     257: invokevirtual #113                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     260: aload         10
     262: invokevirtual #110                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     265: invokevirtual #116                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     268: aconst_null
     269: aload_2
     270: lconst_0
     271: bipush        10
     273: aconst_null
     274: invokespecial #27                 // Method d07/MainKt$main$Trie."<init>":(Ljava/lang/String;Ljava/util/Map;Ld07/MainKt$main$Trie;JILkotlin/jvm/internal/DefaultConstructorMarker;)V
     277: invokeinterface #120,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     282: pop
     283: goto          351
     286: aload         7
     288: ldc           #122                // String $ ls
     290: iconst_0
     291: iconst_2
     292: aconst_null
     293: invokestatic  #59                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     296: ifne          351
     299: aload_2
     300: astore        10
     302: aload         10
     304: aload         10
     306: invokevirtual #126                // Method d07/MainKt$main$Trie.getDirSize:()J
     309: aload         7
     311: checkcast     #61                 // class java/lang/CharSequence
     314: iconst_1
     315: newarray       char
     317: astore        9
     319: aload         9
     321: iconst_0
     322: bipush        32
     324: castore
     325: aload         9
     327: iconst_0
     328: iconst_0
     329: bipush        6
     331: aconst_null
     332: invokestatic  #65                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
     335: iconst_0
     336: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     341: checkcast     #51                 // class java/lang/String
     344: invokestatic  #132                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     347: ladd
     348: invokevirtual #136                // Method d07/MainKt$main$Trie.setDirSize:(J)V
     351: nop
     352: nop
     353: goto          59
     356: nop
     357: new           #138                // class java/util/LinkedHashMap
     360: dup
     361: invokespecial #139                // Method java/util/LinkedHashMap."<init>":()V
     364: checkcast     #93                 // class java/util/Map
     367: astore_3
     368: aload_3
     369: aload_1
     370: invokestatic  #143                // Method main$traverse:(Ljava/util/Map;Ld07/MainKt$main$Trie;)J
     373: pop2
     374: aload_3
     375: invokeinterface #147,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     380: checkcast     #29                 // class java/lang/Iterable
     383: astore        4
     385: lconst_0
     386: lstore        5
     388: aload         4
     390: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     395: astore        7
     397: aload         7
     399: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     404: ifeq          460
     407: aload         7
     409: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     414: astore        8
     416: lload         5
     418: aload         8
     420: checkcast     #149                // class java/lang/Number
     423: invokevirtual #152                // Method java/lang/Number.longValue:()J
     426: lstore        9
     428: lstore        16
     430: iconst_0
     431: istore        11
     433: lload         9
     435: ldc2_w        #153                // long 100000l
     438: lcmp
     439: ifgt          447
     442: lload         9
     444: goto          448
     447: lconst_0
     448: lstore        18
     450: lload         16
     452: lload         18
     454: ladd
     455: lstore        5
     457: goto          397
     460: lload         5
     462: lstore        4
     464: getstatic     #160                // Field java/lang/System.out:Ljava/io/PrintStream;
     467: lload         4
     469: invokevirtual #165                // Method java/io/PrintStream.println:(J)V
     472: aload_3
     473: ldc           #24                 // String /
     475: invokeinterface #96,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     480: dup
     481: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     484: checkcast     #149                // class java/lang/Number
     487: invokevirtual #152                // Method java/lang/Number.longValue:()J
     490: lstore        4
     492: aload_3
     493: invokeinterface #147,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     498: checkcast     #29                 // class java/lang/Iterable
     501: astore        6
     503: iconst_0
     504: istore        7
     506: aload         6
     508: astore        8
     510: new           #167                // class java/util/ArrayList
     513: dup
     514: invokespecial #168                // Method java/util/ArrayList."<init>":()V
     517: checkcast     #170                // class java/util/Collection
     520: astore        9
     522: iconst_0
     523: istore        10
     525: aload         8
     527: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     532: astore        11
     534: aload         11
     536: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     541: ifeq          603
     544: aload         11
     546: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     551: astore        12
     553: aload         12
     555: checkcast     #149                // class java/lang/Number
     558: invokevirtual #152                // Method java/lang/Number.longValue:()J
     561: lstore        13
     563: iconst_0
     564: istore        15
     566: ldc           #171                // int 70000000
     568: i2l
     569: lload         4
     571: lsub
     572: lload         13
     574: ladd
     575: ldc2_w        #172                // long 30000000l
     578: lcmp
     579: iflt          586
     582: iconst_1
     583: goto          587
     586: iconst_0
     587: ifeq          534
     590: aload         9
     592: aload         12
     594: invokeinterface #177,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     599: pop
     600: goto          534
     603: aload         9
     605: checkcast     #67                 // class java/util/List
     608: nop
     609: checkcast     #29                 // class java/lang/Iterable
     612: invokestatic  #181                // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     615: checkcast     #149                // class java/lang/Number
     618: invokevirtual #152                // Method java/lang/Number.longValue:()J
     621: lstore        6
     623: getstatic     #160                // Field java/lang/System.out:Ljava/io/PrintStream;
     626: lload         6
     628: invokevirtual #165                // Method java/io/PrintStream.println:(J)V
     631: return

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

  private static final long main$traverse(java.util.Map<java.lang.String, java.lang.Long>, d07.MainKt$main$Trie);
    Code:
       0: aload_1
       1: invokevirtual #126                // Method d07/MainKt$main$Trie.getDirSize:()J
       4: aload_1
       5: invokevirtual #91                 // Method d07/MainKt$main$Trie.getChildren:()Ljava/util/Map;
       8: invokeinterface #147,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      13: checkcast     #29                 // class java/lang/Iterable
      16: astore        4
      18: lstore        11
      20: lconst_0
      21: lstore        5
      23: aload         4
      25: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      30: astore        7
      32: aload         7
      34: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          83
      42: aload         7
      44: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        8
      51: lload         5
      53: aload         8
      55: checkcast     #22                 // class d07/MainKt$main$Trie
      58: astore        9
      60: lstore        13
      62: iconst_0
      63: istore        10
      65: aload_0
      66: aload         9
      68: invokestatic  #143                // Method main$traverse:(Ljava/util/Map;Ld07/MainKt$main$Trie;)J
      71: lstore        15
      73: lload         13
      75: lload         15
      77: ladd
      78: lstore        5
      80: goto          32
      83: lload         5
      85: lstore        13
      87: lload         11
      89: lload         13
      91: ladd
      92: lstore_2
      93: lload_2
      94: invokestatic  #220                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      97: astore        6
      99: aload_0
     100: aload_1
     101: invokevirtual #106                // Method d07/MainKt$main$Trie.getDir:()Ljava/lang/String;
     104: aload         6
     106: invokeinterface #120,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     111: pop
     112: lload_2
     113: lreturn
}