import java.util.*

fun main() {
    val testInput = readInput("Day17_test")[0]
    check(part1(testInput) == 3068)
    check(part2(testInput) == 1514285714288L)

    val input = readInput("Day17")[0]
    println(part1(input))
    println(part2(input))
}

private const val PART1_ROCKS_COUNT = 2022
private const val PART2_ROCKS_COUNT = 1_000_000_000_000L

private fun part1(input: String): Int {
    val shifter = Shifter(input)
    val cave = LinkedList<Int>()
    val generator = RockGenerator()

    repeat(PART1_ROCKS_COUNT) {
        val rock = generator.nextRock()
        cave.fall(rock, shifter)
    }

    return cave.size
}

private const val PATTERN_SIZE = 20

private fun part2(input: String): Long {
    val shifter = Shifter(input)
    val cave = LinkedList<Int>()
    val generator = RockGenerator()

    var pattern: List<Int>? = null
    var patternFoundIteration = 0L
    var patternFoundCaveSize = 0
    var skippedCaveSize = 0L

    var count = PART2_ROCKS_COUNT
    while (count > 0) {
        val rock = generator.nextRock()
        cave.fall(rock, shifter)

        --count

        //State of the cave repeats iteratively. Find this repetition and use it to skip the huge amount of calculations
        if (pattern == null) {
            //Try to find pattern
            val index = cave.findPattern(PATTERN_SIZE)
            if (index >= 0) {
                pattern = cave.takeLast(PATTERN_SIZE)
                patternFoundIteration = count
                patternFoundCaveSize = cave.size
            }
        } else {
            //Wait for the next repetition of the pattern
            if (cave.subList(cave.size - PATTERN_SIZE, cave.size) == pattern) {
                val rocksPerIteration = patternFoundIteration - count
                val caveIncreasePerIteration = cave.size - patternFoundCaveSize

                val skippedIterations = count / rocksPerIteration
                skippedCaveSize = skippedIterations * caveIncreasePerIteration
                count %= rocksPerIteration
            }
        }
    }

    return skippedCaveSize + cave.size
}

private fun List<Int>.findPattern(patternSize: Int): Int {
    if (this.size < 2 * patternSize) {
        return -1
    }

    val tail = this.subList(this.size - patternSize, this.size)
    for (i in (this.size - patternSize) downTo patternSize) {
        if (tail == this.subList(i - patternSize, i)) {
            return i
        }
    }

    return -1
}

private fun LinkedList<Int>.fall(rock: IntArray, shifter: Shifter) {
    val caveRows = IntArray(rock.size)

    //First 4 shifts happen before rock will rich the most top row of the cave
    repeat(4) {
        shifter.next().invoke(rock, caveRows)
    }

    var bottom = this.lastIndex

    while (true) {
        if (bottom == -1) {
            break
        }

        for (i in caveRows.lastIndex downTo 1) {
            caveRows[i] = caveRows[i - 1]
        }
        caveRows[0] = this[bottom]

        val canFall = rock.foldIndexed(true) { i, acc, value -> acc && (value and caveRows[i] == 0) }
        if (canFall) {
            --bottom
        } else {
            break
        }

        shifter.next().invoke(rock, caveRows)
    }

    rock.forEachIndexed { i, value ->
        if ((bottom + i + 1) in this.indices) {
            this[bottom + i + 1] = this[bottom + i + 1] or value
        } else {
            this.addLast(value)
        }
    }
}

private const val LEFT_BORDER = 0b1000000
private const val RIGHT_BORDER = 0b0000001

class Shifter(private val pattern: String) {
    private var current: Int = 0

    private val left: (IntArray, IntArray) -> Unit = { rock, caveRows ->
        val canShift = rock.foldIndexed(true) { i, acc, value ->
            acc && ((value and LEFT_BORDER) == 0) && ((value shl 1) and caveRows[i] == 0)
        }

        if (canShift) {
            rock.forEachIndexed { i, value -> rock[i] = value shl 1 }
        }
    }

    private val right: (IntArray, IntArray) -> Unit = { rock, caveRows ->
        val canShift = rock.foldIndexed(true) { i, acc, value ->
            acc && (value and RIGHT_BORDER == 0) && ((value shr 1) and caveRows[i] == 0)
        }

        if (canShift) {
            rock.forEachIndexed { i, value -> rock[i] = value shr 1 }
        }
    }

    fun next(): (IntArray, IntArray) -> Unit {
        return (if (pattern[current] == '<') left else right).also {
            current = (current + 1) % pattern.length
        }
    }
}

private class RockGenerator {
    private var i = 0
    val rocks = listOf(
        intArrayOf(
            0b0011110,
        ),
        intArrayOf(
            0b0001000,
            0b0011100,
            0b0001000,
        ),
        intArrayOf(
            0b0011100,
            0b0000100,
            0b0000100,
        ),
        intArrayOf(
            0b0010000,
            0b0010000,
            0b0010000,
            0b0010000,
        ),
        intArrayOf(
            0b0011000,
            0b0011000,
        ),
    )

    fun nextRock(): IntArray {
        return rocks[i].copyOf().also {
            i = (i + 1) % rocks.size
        }
    }
}

Compiled from "Day17.kt"
public final class Day17Kt {
  private static final int PART1_ROCKS_COUNT;

  private static final long PART2_ROCKS_COUNT;

  private static final int PATTERN_SIZE;

  private static final int LEFT_BORDER;

  private static final int RIGHT_BORDER;

  public static final void main();
    Code:
       0: ldc           #8                  // String Day17_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: iconst_0
       6: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      11: checkcast     #22                 // class java/lang/String
      14: astore_0
      15: aload_0
      16: invokestatic  #26                 // Method part1:(Ljava/lang/String;)I
      19: sipush        3068
      22: if_icmpne     29
      25: iconst_1
      26: goto          30
      29: iconst_0
      30: ifne          43
      33: new           #28                 // class java/lang/IllegalStateException
      36: dup
      37: ldc           #30                 // String Check failed.
      39: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      42: athrow
      43: aload_0
      44: invokestatic  #38                 // Method part2:(Ljava/lang/String;)J
      47: ldc2_w        #39                 // long 1514285714288l
      50: lcmp
      51: ifne          58
      54: iconst_1
      55: goto          59
      58: iconst_0
      59: ifne          72
      62: new           #28                 // class java/lang/IllegalStateException
      65: dup
      66: ldc           #30                 // String Check failed.
      68: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      71: athrow
      72: ldc           #42                 // String Day17
      74: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      77: iconst_0
      78: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      83: checkcast     #22                 // class java/lang/String
      86: astore_1
      87: aload_1
      88: invokestatic  #26                 // Method part1:(Ljava/lang/String;)I
      91: istore_2
      92: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
      95: iload_2
      96: invokevirtual #54                 // Method java/io/PrintStream.println:(I)V
      99: aload_1
     100: invokestatic  #38                 // Method part2:(Ljava/lang/String;)J
     103: lstore_2
     104: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
     107: lload_2
     108: invokevirtual #57                 // Method java/io/PrintStream.println:(J)V
     111: return

  private static final int part1(java.lang.String);
    Code:
       0: new           #62                 // class Shifter
       3: dup
       4: aload_0
       5: invokespecial #63                 // Method Shifter."<init>":(Ljava/lang/String;)V
       8: astore_1
       9: new           #65                 // class java/util/LinkedList
      12: dup
      13: invokespecial #67                 // Method java/util/LinkedList."<init>":()V
      16: astore_2
      17: new           #69                 // class RockGenerator
      20: dup
      21: invokespecial #70                 // Method RockGenerator."<init>":()V
      24: astore_3
      25: sipush        2022
      28: istore        4
      30: iconst_0
      31: istore        5
      33: iload         5
      35: iload         4
      37: if_icmpge     67
      40: iload         5
      42: istore        6
      44: iconst_0
      45: istore        7
      47: aload_3
      48: invokevirtual #74                 // Method RockGenerator.nextRock:()[I
      51: astore        8
      53: aload_2
      54: aload         8
      56: aload_1
      57: invokestatic  #78                 // Method fall:(Ljava/util/LinkedList;[ILShifter;)V
      60: nop
      61: iinc          5, 1
      64: goto          33
      67: aload_2
      68: invokevirtual #82                 // Method java/util/LinkedList.size:()I
      71: ireturn

  private static final long part2(java.lang.String);
    Code:
       0: new           #62                 // class Shifter
       3: dup
       4: aload_0
       5: invokespecial #63                 // Method Shifter."<init>":(Ljava/lang/String;)V
       8: astore_1
       9: new           #65                 // class java/util/LinkedList
      12: dup
      13: invokespecial #67                 // Method java/util/LinkedList."<init>":()V
      16: astore_2
      17: new           #69                 // class RockGenerator
      20: dup
      21: invokespecial #70                 // Method RockGenerator."<init>":()V
      24: astore_3
      25: aconst_null
      26: astore        4
      28: lconst_0
      29: lstore        5
      31: iconst_0
      32: istore        7
      34: lconst_0
      35: lstore        8
      37: ldc2_w        #94                 // long 1000000000000l
      40: lstore        10
      42: lload         10
      44: lconst_0
      45: lcmp
      46: ifle          179
      49: aload_3
      50: invokevirtual #74                 // Method RockGenerator.nextRock:()[I
      53: astore        12
      55: aload_2
      56: aload         12
      58: aload_1
      59: invokestatic  #78                 // Method fall:(Ljava/util/LinkedList;[ILShifter;)V
      62: lload         10
      64: ldc2_w        #96                 // long -1l
      67: ladd
      68: lstore        10
      70: aload         4
      72: ifnonnull     115
      75: aload_2
      76: checkcast     #16                 // class java/util/List
      79: bipush        20
      81: invokestatic  #101                // Method findPattern:(Ljava/util/List;I)I
      84: istore        13
      86: iload         13
      88: iflt          42
      91: aload_2
      92: checkcast     #16                 // class java/util/List
      95: bipush        20
      97: invokestatic  #107                // Method kotlin/collections/CollectionsKt.takeLast:(Ljava/util/List;I)Ljava/util/List;
     100: astore        4
     102: lload         10
     104: lstore        5
     106: aload_2
     107: invokevirtual #82                 // Method java/util/LinkedList.size:()I
     110: istore        7
     112: goto          42
     115: aload_2
     116: aload_2
     117: invokevirtual #82                 // Method java/util/LinkedList.size:()I
     120: bipush        20
     122: isub
     123: aload_2
     124: invokevirtual #82                 // Method java/util/LinkedList.size:()I
     127: invokevirtual #111                // Method java/util/LinkedList.subList:(II)Ljava/util/List;
     130: aload         4
     132: invokestatic  #117                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     135: ifeq          42
     138: lload         5
     140: lload         10
     142: lsub
     143: lstore        13
     145: aload_2
     146: invokevirtual #82                 // Method java/util/LinkedList.size:()I
     149: iload         7
     151: isub
     152: istore        15
     154: lload         10
     156: lload         13
     158: ldiv
     159: lstore        16
     161: lload         16
     163: iload         15
     165: i2l
     166: lmul
     167: lstore        8
     169: lload         10
     171: lload         13
     173: lrem
     174: lstore        10
     176: goto          42
     179: lload         8
     181: aload_2
     182: invokevirtual #82                 // Method java/util/LinkedList.size:()I
     185: i2l
     186: ladd
     187: lreturn

  private static final int findPattern(java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_0
       1: invokeinterface #131,  1          // InterfaceMethod java/util/List.size:()I
       6: iconst_2
       7: iload_1
       8: imul
       9: if_icmpge     14
      12: iconst_m1
      13: ireturn
      14: aload_0
      15: aload_0
      16: invokeinterface #131,  1          // InterfaceMethod java/util/List.size:()I
      21: iload_1
      22: isub
      23: aload_0
      24: invokeinterface #131,  1          // InterfaceMethod java/util/List.size:()I
      29: invokeinterface #132,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      34: astore_2
      35: aload_0
      36: invokeinterface #131,  1          // InterfaceMethod java/util/List.size:()I
      41: iload_1
      42: isub
      43: istore_3
      44: iload_1
      45: iload_3
      46: if_icmpgt     79
      49: aload_2
      50: aload_0
      51: iload_3
      52: iload_1
      53: isub
      54: iload_3
      55: invokeinterface #132,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      60: invokestatic  #117                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      63: ifeq          68
      66: iload_3
      67: ireturn
      68: iload_3
      69: iload_1
      70: if_icmpeq     79
      73: iinc          3, -1
      76: goto          49
      79: iconst_m1
      80: ireturn

  private static final void fall(java.util.LinkedList<java.lang.Integer>, int[], Shifter);
    Code:
       0: aload_1
       1: arraylength
       2: newarray       int
       4: astore_3
       5: iconst_4
       6: istore        4
       8: iconst_0
       9: istore        5
      11: iload         5
      13: iload         4
      15: if_icmpge     44
      18: iload         5
      20: istore        6
      22: iconst_0
      23: istore        7
      25: aload_2
      26: invokevirtual #141                // Method Shifter.next:()Lkotlin/jvm/functions/Function2;
      29: aload_1
      30: aload_3
      31: invokeinterface #147,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      36: pop
      37: nop
      38: iinc          5, 1
      41: goto          11
      44: iconst_0
      45: istore        4
      47: aload_0
      48: checkcast     #16                 // class java/util/List
      51: invokestatic  #151                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      54: istore        4
      56: nop
      57: iload         4
      59: iconst_m1
      60: if_icmpne     66
      63: goto          235
      66: aload_3
      67: invokestatic  #156                // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      70: istore        5
      72: iconst_0
      73: iload         5
      75: if_icmpge     94
      78: aload_3
      79: iload         5
      81: aload_3
      82: iload         5
      84: iconst_1
      85: isub
      86: iaload
      87: iastore
      88: iinc          5, -1
      91: goto          72
      94: aload_3
      95: iconst_0
      96: aload_0
      97: iload         4
      99: invokevirtual #157                // Method java/util/LinkedList.get:(I)Ljava/lang/Object;
     102: dup
     103: ldc           #159                // String get(...)
     105: invokestatic  #163                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     108: checkcast     #165                // class java/lang/Number
     111: invokevirtual #168                // Method java/lang/Number.intValue:()I
     114: iastore
     115: aload_1
     116: astore        6
     118: iconst_1
     119: istore        7
     121: iconst_0
     122: istore        8
     124: iconst_0
     125: istore        9
     127: iload         7
     129: istore        10
     131: iconst_0
     132: istore        11
     134: aload         6
     136: arraylength
     137: istore        12
     139: iload         11
     141: iload         12
     143: if_icmpge     199
     146: aload         6
     148: iload         11
     150: iaload
     151: istore        13
     153: iload         9
     155: iinc          9, 1
     158: iload         10
     160: iload         13
     162: istore        14
     164: istore        15
     166: istore        16
     168: iconst_0
     169: istore        17
     171: iload         15
     173: ifeq          190
     176: iload         14
     178: aload_3
     179: iload         16
     181: iaload
     182: iand
     183: ifne          190
     186: iconst_1
     187: goto          191
     190: iconst_0
     191: istore        10
     193: iinc          11, 1
     196: goto          139
     199: iload         10
     201: istore        5
     203: iload         5
     205: ifeq          217
     208: iload         4
     210: iconst_m1
     211: iadd
     212: istore        4
     214: goto          220
     217: goto          235
     220: aload_2
     221: invokevirtual #141                // Method Shifter.next:()Lkotlin/jvm/functions/Function2;
     224: aload_1
     225: aload_3
     226: invokeinterface #147,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     231: pop
     232: goto          56
     235: aload_1
     236: astore        5
     238: iconst_0
     239: istore        6
     241: iconst_0
     242: istore        7
     244: iconst_0
     245: istore        8
     247: aload         5
     249: arraylength
     250: istore        9
     252: iload         8
     254: iload         9
     256: if_icmpge     380
     259: aload         5
     261: iload         8
     263: iaload
     264: istore        10
     266: iload         7
     268: iinc          7, 1
     271: iload         10
     273: istore        11
     275: istore        12
     277: iconst_0
     278: istore        13
     280: aload_0
     281: checkcast     #170                // class java/util/Collection
     284: invokeinterface #171,  1          // InterfaceMethod java/util/Collection.size:()I
     289: istore        14
     291: iload         4
     293: iload         12
     295: iadd
     296: iconst_1
     297: iadd
     298: istore        15
     300: iconst_0
     301: iload         15
     303: if_icmpgt     321
     306: iload         15
     308: iload         14
     310: if_icmpge     317
     313: iconst_1
     314: goto          322
     317: iconst_0
     318: goto          322
     321: iconst_0
     322: ifeq          363
     325: aload_0
     326: iload         4
     328: iload         12
     330: iadd
     331: iconst_1
     332: iadd
     333: aload_0
     334: iload         4
     336: iload         12
     338: iadd
     339: iconst_1
     340: iadd
     341: invokevirtual #157                // Method java/util/LinkedList.get:(I)Ljava/lang/Object;
     344: checkcast     #165                // class java/lang/Number
     347: invokevirtual #168                // Method java/lang/Number.intValue:()I
     350: iload         11
     352: ior
     353: invokestatic  #177                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     356: invokevirtual #181                // Method java/util/LinkedList.set:(ILjava/lang/Object;)Ljava/lang/Object;
     359: pop
     360: goto          372
     363: aload_0
     364: iload         11
     366: invokestatic  #177                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     369: invokevirtual #185                // Method java/util/LinkedList.addLast:(Ljava/lang/Object;)V
     372: nop
     373: nop
     374: iinc          8, 1
     377: goto          252
     380: nop
     381: return

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


import java.util.*

fun main() {
    val testInput = readInput("Day07_test")
    val testRoot = buildFileSystem(testInput)
    val testSizeCache = mutableMapOf<Node, Long>()
    check(part1(testRoot, testSizeCache) == 95437L)
    check(part2(testRoot, testSizeCache) == 24933642L)

    val input = readInput("Day07")
    val root = buildFileSystem(input)
    val sizeCache = mutableMapOf<Node, Long>()
    println(part1(root, sizeCache))
    println(part2(root, sizeCache))
}

private const val MAX = 100000L
private fun part1(root: Node, sizeCache: MutableMap<Node, Long>): Long {
    var result = 0L
    root.visit { node ->
        if (node.isDir) {
            val size = sizeCache.getOrPut(node, node::size)

            if (size < MAX) {
                result += size
            }
        }
    }

    return result
}

private const val TOTAL_SPACE = 70000000L
private const val TARGET_FREE_SPACE = 30000000L
private fun part2(root: Node, sizeCache: MutableMap<Node, Long>): Long {
    val rootSize = sizeCache.getOrPut(root, root::size)
    val spaceToFreeUp = TARGET_FREE_SPACE - (TOTAL_SPACE - rootSize)

    var result = Long.MAX_VALUE
    root.visit { node ->
        if (node.isDir) {
            val size = sizeCache.getOrPut(node, node::size)

            if (size >= spaceToFreeUp && size < result) {
                result = size
            }
        }
    }

    return result
}

private fun buildFileSystem(commands: List<String>): Node {
    val root = Node.Dir()
    val navigationStack = LinkedList<Node>()

    var i = 0
    while (i <= commands.lastIndex) {
        val cmd = commands[i++]

        when {
            cmd.startsWith("$ cd /") -> {
                navigationStack.clear()
                navigationStack.push(root)
            }
            cmd.startsWith("$ cd ..") -> navigationStack.pop()
            cmd.startsWith("$ cd ") -> {
                val destinationName = cmd.substringAfter("$ cd ")
                val destination = navigationStack.peek().getChild(destinationName)
                navigationStack.push(destination)
            }
            cmd.startsWith("$ ls") -> {
                val targetNode = navigationStack.peek()

                while (i <= commands.lastIndex && !commands[i].startsWith("$")) {
                    val item = commands[i++]
                    if (item.startsWith("dir")) {
                        targetNode.addChild(
                            name = item.substringAfter("dir "),
                            child = Node.Dir()
                        )
                    } else {
                        targetNode.addChild(
                            name = item.substringAfter(" "),
                            child = Node.File(
                                size = item.substringBefore(" ").toLong()
                            )
                        )
                    }
                }
            }
        }
    }

    return root
}

sealed interface Node {
    val isDir: Boolean
    fun getChild(name: String): Node
    fun addChild(name: String, child: Node)
    fun size(): Long
    fun visit(action: (Node) -> Unit)

    class Dir : Node {
        private val children = mutableMapOf<String, Node>()

        override val isDir: Boolean
            get() = true

        override fun getChild(name: String): Node = children[name] ?: error("Child $name not found")
        override fun addChild(name: String, child: Node) {
            children[name] = child
        }

        override fun size(): Long {
            return children.values.fold(0) { acc, node -> acc + node.size() }
        }

        override fun visit(action: (Node) -> Unit) {
            children.forEach { it.value.visit(action) }
            action(this)
        }
    }

    class File(val size: Long) : Node {
        override val isDir: Boolean
            get() = false

        override fun getChild(name: String): Node = error("getChild is not applicable for File")
        override fun addChild(name: String, child: Node) = error("addChild is not applicable for File")
        override fun size(): Long = size

        override fun visit(action: (Node) -> Unit) {
            action(this)
        }
    }
}

Compiled from "Day07.kt"
public final class Day07Kt {
  private static final long MAX;

  private static final long TOTAL_SPACE;

  private static final long TARGET_FREE_SPACE;

  public static final void main();
    Code:
       0: ldc           #8                  // String Day07_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method buildFileSystem:(Ljava/util/List;)LNode;
      10: astore_1
      11: new           #20                 // class java/util/LinkedHashMap
      14: dup
      15: invokespecial #23                 // Method java/util/LinkedHashMap."<init>":()V
      18: checkcast     #25                 // class java/util/Map
      21: astore_2
      22: aload_1
      23: aload_2
      24: invokestatic  #29                 // Method part1:(LNode;Ljava/util/Map;)J
      27: ldc2_w        #30                 // long 95437l
      30: lcmp
      31: ifne          38
      34: iconst_1
      35: goto          39
      38: iconst_0
      39: ifne          52
      42: new           #33                 // class java/lang/IllegalStateException
      45: dup
      46: ldc           #35                 // String Check failed.
      48: invokespecial #38                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      51: athrow
      52: aload_1
      53: aload_2
      54: invokestatic  #41                 // Method part2:(LNode;Ljava/util/Map;)J
      57: ldc2_w        #42                 // long 24933642l
      60: lcmp
      61: ifne          68
      64: iconst_1
      65: goto          69
      68: iconst_0
      69: ifne          82
      72: new           #33                 // class java/lang/IllegalStateException
      75: dup
      76: ldc           #35                 // String Check failed.
      78: invokespecial #38                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      81: athrow
      82: ldc           #45                 // String Day07
      84: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      87: astore_3
      88: aload_3
      89: invokestatic  #18                 // Method buildFileSystem:(Ljava/util/List;)LNode;
      92: astore        4
      94: new           #20                 // class java/util/LinkedHashMap
      97: dup
      98: invokespecial #23                 // Method java/util/LinkedHashMap."<init>":()V
     101: checkcast     #25                 // class java/util/Map
     104: astore        5
     106: aload         4
     108: aload         5
     110: invokestatic  #29                 // Method part1:(LNode;Ljava/util/Map;)J
     113: lstore        6
     115: getstatic     #51                 // Field java/lang/System.out:Ljava/io/PrintStream;
     118: lload         6
     120: invokevirtual #57                 // Method java/io/PrintStream.println:(J)V
     123: aload         4
     125: aload         5
     127: invokestatic  #41                 // Method part2:(LNode;Ljava/util/Map;)J
     130: lstore        6
     132: getstatic     #51                 // Field java/lang/System.out:Ljava/io/PrintStream;
     135: lload         6
     137: invokevirtual #57                 // Method java/io/PrintStream.println:(J)V
     140: return

  private static final long part1(Node, java.util.Map<Node, java.lang.Long>);
    Code:
       0: new           #73                 // class kotlin/jvm/internal/Ref$LongRef
       3: dup
       4: invokespecial #74                 // Method kotlin/jvm/internal/Ref$LongRef."<init>":()V
       7: astore_2
       8: aload_0
       9: aload_1
      10: aload_2
      11: invokedynamic #94,  0             // InvokeDynamic #0:invoke:(Ljava/util/Map;Lkotlin/jvm/internal/Ref$LongRef;)Lkotlin/jvm/functions/Function1;
      16: invokeinterface #98,  2           // InterfaceMethod Node.visit:(Lkotlin/jvm/functions/Function1;)V
      21: aload_2
      22: getfield      #102                // Field kotlin/jvm/internal/Ref$LongRef.element:J
      25: lreturn

  private static final long part2(Node, java.util.Map<Node, java.lang.Long>);
    Code:
       0: aload_1
       1: astore        4
       3: iconst_0
       4: istore        5
       6: aload         4
       8: aload_0
       9: invokeinterface #107,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      14: astore        6
      16: aload         6
      18: ifnonnull     51
      21: iconst_0
      22: istore        7
      24: aload_0
      25: invokeinterface #111,  1          // InterfaceMethod Node.size:()J
      30: invokestatic  #117                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      33: astore        7
      35: aload         4
      37: aload_0
      38: aload         7
      40: invokeinterface #121,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      45: pop
      46: aload         7
      48: goto          53
      51: aload         6
      53: nop
      54: checkcast     #123                // class java/lang/Number
      57: invokevirtual #126                // Method java/lang/Number.longValue:()J
      60: lstore_2
      61: ldc2_w        #127                // long 30000000l
      64: ldc2_w        #129                // long 70000000l
      67: lload_2
      68: lsub
      69: lsub
      70: lstore        4
      72: new           #73                 // class kotlin/jvm/internal/Ref$LongRef
      75: dup
      76: invokespecial #74                 // Method kotlin/jvm/internal/Ref$LongRef."<init>":()V
      79: astore        6
      81: aload         6
      83: ldc2_w        #131                // long 9223372036854775807l
      86: putfield      #102                // Field kotlin/jvm/internal/Ref$LongRef.element:J
      89: aload_0
      90: aload_1
      91: lload         4
      93: aload         6
      95: invokedynamic #140,  0            // InvokeDynamic #1:invoke:(Ljava/util/Map;JLkotlin/jvm/internal/Ref$LongRef;)Lkotlin/jvm/functions/Function1;
     100: invokeinterface #98,  2           // InterfaceMethod Node.visit:(Lkotlin/jvm/functions/Function1;)V
     105: aload         6
     107: getfield      #102                // Field kotlin/jvm/internal/Ref$LongRef.element:J
     110: lreturn

  private static final Node buildFileSystem(java.util.List<java.lang.String>);
    Code:
       0: new           #152                // class Node$Dir
       3: dup
       4: invokespecial #153                // Method Node$Dir."<init>":()V
       7: astore_1
       8: new           #155                // class java/util/LinkedList
      11: dup
      12: invokespecial #156                // Method java/util/LinkedList."<init>":()V
      15: astore_2
      16: iconst_0
      17: istore_3
      18: iload_3
      19: aload_0
      20: invokestatic  #162                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      23: if_icmpgt     290
      26: aload_0
      27: iload_3
      28: iinc          3, 1
      31: invokeinterface #165,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      36: checkcast     #167                // class java/lang/String
      39: astore        4
      41: nop
      42: aload         4
      44: ldc           #169                // String $ cd /
      46: iconst_0
      47: iconst_2
      48: aconst_null
      49: invokestatic  #175                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      52: ifeq          67
      55: aload_2
      56: invokevirtual #178                // Method java/util/LinkedList.clear:()V
      59: aload_2
      60: aload_1
      61: invokevirtual #182                // Method java/util/LinkedList.push:(Ljava/lang/Object;)V
      64: goto          18
      67: aload         4
      69: ldc           #184                // String $ cd ..
      71: iconst_0
      72: iconst_2
      73: aconst_null
      74: invokestatic  #175                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      77: ifeq          88
      80: aload_2
      81: invokevirtual #188                // Method java/util/LinkedList.pop:()Ljava/lang/Object;
      84: pop
      85: goto          18
      88: aload         4
      90: ldc           #190                // String $ cd
      92: iconst_0
      93: iconst_2
      94: aconst_null
      95: invokestatic  #175                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      98: ifeq          138
     101: aload         4
     103: ldc           #190                // String $ cd
     105: aconst_null
     106: iconst_2
     107: aconst_null
     108: invokestatic  #194                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     111: astore        5
     113: aload_2
     114: invokevirtual #197                // Method java/util/LinkedList.peek:()Ljava/lang/Object;
     117: checkcast     #70                 // class Node
     120: aload         5
     122: invokeinterface #201,  2          // InterfaceMethod Node.getChild:(Ljava/lang/String;)LNode;
     127: astore        6
     129: aload_2
     130: aload         6
     132: invokevirtual #182                // Method java/util/LinkedList.push:(Ljava/lang/Object;)V
     135: goto          18
     138: aload         4
     140: ldc           #203                // String $ ls
     142: iconst_0
     143: iconst_2
     144: aconst_null
     145: invokestatic  #175                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     148: ifeq          18
     151: aload_2
     152: invokevirtual #197                // Method java/util/LinkedList.peek:()Ljava/lang/Object;
     155: checkcast     #70                 // class Node
     158: astore        5
     160: iload_3
     161: aload_0
     162: invokestatic  #162                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     165: if_icmpgt     18
     168: aload_0
     169: iload_3
     170: invokeinterface #165,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     175: checkcast     #167                // class java/lang/String
     178: ldc           #205                // String $
     180: iconst_0
     181: iconst_2
     182: aconst_null
     183: invokestatic  #175                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     186: ifne          18
     189: aload_0
     190: iload_3
     191: iinc          3, 1
     194: invokeinterface #165,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     199: checkcast     #167                // class java/lang/String
     202: astore        6
     204: aload         6
     206: ldc           #207                // String dir
     208: iconst_0
     209: iconst_2
     210: aconst_null
     211: invokestatic  #175                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     214: ifeq          247
     217: aload         5
     219: aload         6
     221: ldc           #209                // String dir
     223: aconst_null
     224: iconst_2
     225: aconst_null
     226: invokestatic  #194                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     229: new           #152                // class Node$Dir
     232: dup
     233: invokespecial #153                // Method Node$Dir."<init>":()V
     236: checkcast     #70                 // class Node
     239: invokeinterface #213,  3          // InterfaceMethod Node.addChild:(Ljava/lang/String;LNode;)V
     244: goto          160
     247: aload         5
     249: aload         6
     251: ldc           #215                // String
     253: aconst_null
     254: iconst_2
     255: aconst_null
     256: invokestatic  #194                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     259: new           #217                // class Node$File
     262: dup
     263: aload         6
     265: ldc           #215                // String
     267: aconst_null
     268: iconst_2
     269: aconst_null
     270: invokestatic  #220                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     273: invokestatic  #224                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     276: invokespecial #226                // Method Node$File."<init>":(J)V
     279: checkcast     #70                 // class Node
     282: invokeinterface #213,  3          // InterfaceMethod Node.addChild:(Ljava/lang/String;LNode;)V
     287: goto          160
     290: aload_1
     291: checkcast     #70                 // class Node
     294: areturn

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

  private static final kotlin.Unit part1$lambda$0(java.util.Map, kotlin.jvm.internal.Ref$LongRef, Node);
    Code:
       0: aload_2
       1: ldc           #244                // String node
       3: invokestatic  #250                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: invokeinterface #254,  1          // InterfaceMethod Node.isDir:()Z
      12: ifeq          94
      15: aload_0
      16: astore        5
      18: iconst_0
      19: istore        6
      21: aload         5
      23: aload_2
      24: invokeinterface #107,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      29: astore        7
      31: aload         7
      33: ifnonnull     66
      36: iconst_0
      37: istore        8
      39: aload_2
      40: invokeinterface #111,  1          // InterfaceMethod Node.size:()J
      45: invokestatic  #117                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      48: astore        8
      50: aload         5
      52: aload_2
      53: aload         8
      55: invokeinterface #121,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      60: pop
      61: aload         8
      63: goto          68
      66: aload         7
      68: nop
      69: checkcast     #123                // class java/lang/Number
      72: invokevirtual #126                // Method java/lang/Number.longValue:()J
      75: lstore_3
      76: lload_3
      77: ldc2_w        #255                // long 100000l
      80: lcmp
      81: ifge          94
      84: aload_1
      85: aload_1
      86: getfield      #102                // Field kotlin/jvm/internal/Ref$LongRef.element:J
      89: lload_3
      90: ladd
      91: putfield      #102                // Field kotlin/jvm/internal/Ref$LongRef.element:J
      94: getstatic     #262                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      97: areturn

  private static final kotlin.Unit part2$lambda$3(java.util.Map, long, kotlin.jvm.internal.Ref$LongRef, Node);
    Code:
       0: aload         4
       2: ldc           #244                // String node
       4: invokestatic  #250                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload         4
       9: invokeinterface #254,  1          // InterfaceMethod Node.isDir:()Z
      14: ifeq          105
      17: aload_0
      18: astore        7
      20: iconst_0
      21: istore        8
      23: aload         7
      25: aload         4
      27: invokeinterface #107,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      32: astore        9
      34: aload         9
      36: ifnonnull     71
      39: iconst_0
      40: istore        10
      42: aload         4
      44: invokeinterface #111,  1          // InterfaceMethod Node.size:()J
      49: invokestatic  #117                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      52: astore        10
      54: aload         7
      56: aload         4
      58: aload         10
      60: invokeinterface #121,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      65: pop
      66: aload         10
      68: goto          73
      71: aload         9
      73: nop
      74: checkcast     #123                // class java/lang/Number
      77: invokevirtual #126                // Method java/lang/Number.longValue:()J
      80: lstore        5
      82: lload         5
      84: lload_1
      85: lcmp
      86: iflt          105
      89: lload         5
      91: aload_3
      92: getfield      #102                // Field kotlin/jvm/internal/Ref$LongRef.element:J
      95: lcmp
      96: ifge          105
      99: aload_3
     100: lload         5
     102: putfield      #102                // Field kotlin/jvm/internal/Ref$LongRef.element:J
     105: getstatic     #262                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     108: areturn
}


fun main() {
    val testInput = readInput("Day06_test")
    check(part1(testInput[0]) == 5)
    check(part1(testInput[1]) == 6)
    check(part1(testInput[2]) == 10)
    check(part1(testInput[3]) == 11)

    check(part2(testInput[0]) == 23)
    check(part2(testInput[1]) == 23)
    check(part2(testInput[2]) == 29)
    check(part2(testInput[3]) == 26)

    val input = readInput("Day06")
    println(part1(input[0]))
    println(part2(input[0]))
}

private fun part1(input: String): Int = findUniqueSequence(input, 4)
private fun part2(input: String): Int = findUniqueSequence(input, 14)

private fun findUniqueSequence(input: String, targetCount: Int): Int {
    val counts = mutableMapOf<Char, Int>()
    repeat(targetCount - 1) { i ->
        counts[input[i]] = counts.getOrDefault(input[i], 0) + 1
    }

    for (i in (targetCount - 1)..input.lastIndex) {
        counts[input[i]] = counts.getOrDefault(input[i], 0) + 1

        if (counts.size == targetCount) {
            return i + 1
        }

        if (counts[input[i - targetCount + 1]] == 1) {
            counts.remove(input[i - targetCount + 1])
        } else {
            counts[input[i - targetCount + 1]] = counts.getValue(input[i - targetCount + 1]) - 1
        }
    }

    error("Not found")
}

Compiled from "Day06.kt"
public final class Day06Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day06_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: iconst_0
       8: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #22                 // class java/lang/String
      16: invokestatic  #26                 // Method part1:(Ljava/lang/String;)I
      19: iconst_5
      20: if_icmpne     27
      23: iconst_1
      24: goto          28
      27: iconst_0
      28: ifne          41
      31: new           #28                 // class java/lang/IllegalStateException
      34: dup
      35: ldc           #30                 // String Check failed.
      37: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      40: athrow
      41: aload_0
      42: iconst_1
      43: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      48: checkcast     #22                 // class java/lang/String
      51: invokestatic  #26                 // Method part1:(Ljava/lang/String;)I
      54: bipush        6
      56: if_icmpne     63
      59: iconst_1
      60: goto          64
      63: iconst_0
      64: ifne          77
      67: new           #28                 // class java/lang/IllegalStateException
      70: dup
      71: ldc           #30                 // String Check failed.
      73: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      76: athrow
      77: aload_0
      78: iconst_2
      79: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      84: checkcast     #22                 // class java/lang/String
      87: invokestatic  #26                 // Method part1:(Ljava/lang/String;)I
      90: bipush        10
      92: if_icmpne     99
      95: iconst_1
      96: goto          100
      99: iconst_0
     100: ifne          113
     103: new           #28                 // class java/lang/IllegalStateException
     106: dup
     107: ldc           #30                 // String Check failed.
     109: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     112: athrow
     113: aload_0
     114: iconst_3
     115: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     120: checkcast     #22                 // class java/lang/String
     123: invokestatic  #26                 // Method part1:(Ljava/lang/String;)I
     126: bipush        11
     128: if_icmpne     135
     131: iconst_1
     132: goto          136
     135: iconst_0
     136: ifne          149
     139: new           #28                 // class java/lang/IllegalStateException
     142: dup
     143: ldc           #30                 // String Check failed.
     145: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     148: athrow
     149: aload_0
     150: iconst_0
     151: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     156: checkcast     #22                 // class java/lang/String
     159: invokestatic  #37                 // Method part2:(Ljava/lang/String;)I
     162: bipush        23
     164: if_icmpne     171
     167: iconst_1
     168: goto          172
     171: iconst_0
     172: ifne          185
     175: new           #28                 // class java/lang/IllegalStateException
     178: dup
     179: ldc           #30                 // String Check failed.
     181: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     184: athrow
     185: aload_0
     186: iconst_1
     187: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     192: checkcast     #22                 // class java/lang/String
     195: invokestatic  #37                 // Method part2:(Ljava/lang/String;)I
     198: bipush        23
     200: if_icmpne     207
     203: iconst_1
     204: goto          208
     207: iconst_0
     208: ifne          221
     211: new           #28                 // class java/lang/IllegalStateException
     214: dup
     215: ldc           #30                 // String Check failed.
     217: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     220: athrow
     221: aload_0
     222: iconst_2
     223: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     228: checkcast     #22                 // class java/lang/String
     231: invokestatic  #37                 // Method part2:(Ljava/lang/String;)I
     234: bipush        29
     236: if_icmpne     243
     239: iconst_1
     240: goto          244
     243: iconst_0
     244: ifne          257
     247: new           #28                 // class java/lang/IllegalStateException
     250: dup
     251: ldc           #30                 // String Check failed.
     253: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     256: athrow
     257: aload_0
     258: iconst_3
     259: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     264: checkcast     #22                 // class java/lang/String
     267: invokestatic  #37                 // Method part2:(Ljava/lang/String;)I
     270: bipush        26
     272: if_icmpne     279
     275: iconst_1
     276: goto          280
     279: iconst_0
     280: ifne          293
     283: new           #28                 // class java/lang/IllegalStateException
     286: dup
     287: ldc           #30                 // String Check failed.
     289: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     292: athrow
     293: ldc           #39                 // String Day06
     295: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
     298: astore_1
     299: aload_1
     300: iconst_0
     301: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     306: checkcast     #22                 // class java/lang/String
     309: invokestatic  #26                 // Method part1:(Ljava/lang/String;)I
     312: istore_2
     313: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
     316: iload_2
     317: invokevirtual #51                 // Method java/io/PrintStream.println:(I)V
     320: aload_1
     321: iconst_0
     322: invokeinterface #20,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     327: checkcast     #22                 // class java/lang/String
     330: invokestatic  #37                 // Method part2:(Ljava/lang/String;)I
     333: istore_2
     334: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
     337: iload_2
     338: invokevirtual #51                 // Method java/io/PrintStream.println:(I)V
     341: return

  private static final int part1(java.lang.String);
    Code:
       0: aload_0
       1: iconst_4
       2: invokestatic  #58                 // Method findUniqueSequence:(Ljava/lang/String;I)I
       5: ireturn

  private static final int part2(java.lang.String);
    Code:
       0: aload_0
       1: bipush        14
       3: invokestatic  #58                 // Method findUniqueSequence:(Ljava/lang/String;I)I
       6: ireturn

  private static final int findUniqueSequence(java.lang.String, int);
    Code:
       0: new           #61                 // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #63                 // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #65                 // class java/util/Map
      10: astore_2
      11: iload_1
      12: iconst_1
      13: isub
      14: istore_3
      15: iconst_0
      16: istore        4
      18: iload         4
      20: iload_3
      21: if_icmpge     84
      24: iload         4
      26: istore        5
      28: iconst_0
      29: istore        6
      31: aload_2
      32: aload_0
      33: iload         5
      35: invokevirtual #69                 // Method java/lang/String.charAt:(I)C
      38: invokestatic  #75                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      41: aload_2
      42: aload_0
      43: iload         5
      45: invokevirtual #69                 // Method java/lang/String.charAt:(I)C
      48: invokestatic  #75                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      51: iconst_0
      52: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: invokeinterface #84,  3           // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      60: checkcast     #86                 // class java/lang/Number
      63: invokevirtual #90                 // Method java/lang/Number.intValue:()I
      66: iconst_1
      67: iadd
      68: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      71: invokeinterface #93,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      76: pop
      77: nop
      78: iinc          4, 1
      81: goto          18
      84: iload_1
      85: iconst_1
      86: isub
      87: istore_3
      88: aload_0
      89: checkcast     #95                 // class java/lang/CharSequence
      92: invokestatic  #101                // Method kotlin/text/StringsKt.getLastIndex:(Ljava/lang/CharSequence;)I
      95: istore        4
      97: iload_3
      98: iload         4
     100: if_icmpgt     281
     103: aload_2
     104: aload_0
     105: iload_3
     106: invokevirtual #69                 // Method java/lang/String.charAt:(I)C
     109: invokestatic  #75                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     112: aload_2
     113: aload_0
     114: iload_3
     115: invokevirtual #69                 // Method java/lang/String.charAt:(I)C
     118: invokestatic  #75                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     121: iconst_0
     122: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     125: invokeinterface #84,  3           // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     130: checkcast     #86                 // class java/lang/Number
     133: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     136: iconst_1
     137: iadd
     138: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     141: invokeinterface #93,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     146: pop
     147: aload_2
     148: invokeinterface #104,  1          // InterfaceMethod java/util/Map.size:()I
     153: iload_1
     154: if_icmpne     161
     157: iload_3
     158: iconst_1
     159: iadd
     160: ireturn
     161: aload_2
     162: aload_0
     163: iload_3
     164: iload_1
     165: isub
     166: iconst_1
     167: iadd
     168: invokevirtual #69                 // Method java/lang/String.charAt:(I)C
     171: invokestatic  #75                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     174: invokeinterface #107,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     179: checkcast     #77                 // class java/lang/Integer
     182: iconst_1
     183: istore        5
     185: dup
     186: ifnonnull     193
     189: pop
     190: goto          223
     193: invokevirtual #108                // Method java/lang/Integer.intValue:()I
     196: iload         5
     198: if_icmpne     223
     201: aload_2
     202: aload_0
     203: iload_3
     204: iload_1
     205: isub
     206: iconst_1
     207: iadd
     208: invokevirtual #69                 // Method java/lang/String.charAt:(I)C
     211: invokestatic  #75                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     214: invokeinterface #111,  2          // InterfaceMethod java/util/Map.remove:(Ljava/lang/Object;)Ljava/lang/Object;
     219: pop
     220: goto          269
     223: aload_2
     224: aload_0
     225: iload_3
     226: iload_1
     227: isub
     228: iconst_1
     229: iadd
     230: invokevirtual #69                 // Method java/lang/String.charAt:(I)C
     233: invokestatic  #75                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     236: aload_2
     237: aload_0
     238: iload_3
     239: iload_1
     240: isub
     241: iconst_1
     242: iadd
     243: invokevirtual #69                 // Method java/lang/String.charAt:(I)C
     246: invokestatic  #75                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     249: invokestatic  #117                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     252: checkcast     #86                 // class java/lang/Number
     255: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     258: iconst_1
     259: isub
     260: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     263: invokeinterface #93,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     268: pop
     269: iload_3
     270: iload         4
     272: if_icmpeq     281
     275: iinc          3, 1
     278: goto          103
     281: new           #28                 // class java/lang/IllegalStateException
     284: dup
     285: ldc           #119                // String Not found
     287: invokevirtual #123                // Method java/lang/Object.toString:()Ljava/lang/String;
     290: invokespecial #34                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     293: athrow

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