import kotlin.math.absoluteValue
import kotlin.math.sign

private data class Cell(var x: Int = 0, var y: Int = 0) {

    fun move(other: Cell) {
        x += other.x
        y += other.y
    }

    fun isAttached(other: Cell) = (x - other.x).absoluteValue < 2 && (y - other.y).absoluteValue < 2

    fun follow(other: Cell) {
        x += (other.x - x).sign
        y += (other.y - y).sign
    }
}

private fun moveTheRope(moves: List<String>, rope: List<Cell>): Int {
    val res = HashSet<Cell>()
    res.add(Cell())

    for (move in moves) {
        val (direction, value) = move.split(" ")
        val step = when (direction) {
            "R" -> Cell(1)
            "L" -> Cell(-1)
            "U" -> Cell(y = 1)
            "D" -> Cell(y = -1)
            else -> error("incorrect input")
        }

        for (i in 0 until value.toInt()) {
            rope.first().move(step)

            for (j in 1 until rope.size) {
                if (rope[j].isAttached(rope[j - 1])) continue

                rope[j].follow(rope[j - 1])
            }

            res.add(rope.last().copy())
        }
    }

    return res.size
}

fun main() {
    fun part1(input: List<String>) = moveTheRope(input, List(2) { Cell() })

    fun part2(input: List<String>) = moveTheRope(input, List(10) { Cell() })

    // test if implementation meets criteria from the description, like:
    val testInput = readInput("Day09_test")
    check(part1(testInput) == 13)
    check(part2(testInput) == 1)

    val input = readInput("Day09")
    println(part1(input))
    println(part2(input))
}

Compiled from "Day09.kt"
public final class Day09Kt {
  private static final int moveTheRope(java.util.List<java.lang.String>, java.util.List<Cell>);
    Code:
       0: new           #9                  // class java/util/HashSet
       3: dup
       4: invokespecial #13                 // Method java/util/HashSet."<init>":()V
       7: astore_2
       8: aload_2
       9: new           #15                 // class Cell
      12: dup
      13: iconst_0
      14: iconst_0
      15: iconst_3
      16: aconst_null
      17: invokespecial #18                 // Method Cell."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      20: invokevirtual #22                 // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      23: pop
      24: aload_0
      25: invokeinterface #28,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      30: astore_3
      31: aload_3
      32: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          414
      40: aload_3
      41: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: checkcast     #40                 // class java/lang/String
      49: astore        4
      51: aload         4
      53: checkcast     #42                 // class java/lang/CharSequence
      56: iconst_1
      57: anewarray     #40                 // class java/lang/String
      60: astore        6
      62: aload         6
      64: iconst_0
      65: ldc           #44                 // String
      67: aastore
      68: aload         6
      70: iconst_0
      71: iconst_0
      72: bipush        6
      74: aconst_null
      75: invokestatic  #50                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      78: astore        5
      80: aload         5
      82: iconst_0
      83: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #40                 // class java/lang/String
      91: astore        6
      93: aload         5
      95: iconst_1
      96: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     101: checkcast     #40                 // class java/lang/String
     104: astore        7
     106: aload         6
     108: astore        9
     110: aload         9
     112: invokevirtual #58                 // Method java/lang/String.hashCode:()I
     115: lookupswitch  { // 4
                    68: 169
                    76: 195
                    82: 156
                    85: 182
               default: 264
          }
     156: aload         9
     158: ldc           #60                 // String R
     160: invokevirtual #63                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     163: ifne          208
     166: goto          264
     169: aload         9
     171: ldc           #65                 // String D
     173: invokevirtual #63                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     176: ifne          250
     179: goto          264
     182: aload         9
     184: ldc           #67                 // String U
     186: invokevirtual #63                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     189: ifne          236
     192: goto          264
     195: aload         9
     197: ldc           #69                 // String L
     199: invokevirtual #63                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     202: ifne          222
     205: goto          264
     208: new           #15                 // class Cell
     211: dup
     212: iconst_1
     213: iconst_0
     214: iconst_2
     215: aconst_null
     216: invokespecial #18                 // Method Cell."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     219: goto          277
     222: new           #15                 // class Cell
     225: dup
     226: iconst_m1
     227: iconst_0
     228: iconst_2
     229: aconst_null
     230: invokespecial #18                 // Method Cell."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     233: goto          277
     236: new           #15                 // class Cell
     239: dup
     240: iconst_0
     241: iconst_1
     242: iconst_1
     243: aconst_null
     244: invokespecial #18                 // Method Cell."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     247: goto          277
     250: new           #15                 // class Cell
     253: dup
     254: iconst_0
     255: iconst_m1
     256: iconst_1
     257: aconst_null
     258: invokespecial #18                 // Method Cell."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     261: goto          277
     264: new           #71                 // class java/lang/IllegalStateException
     267: dup
     268: ldc           #73                 // String incorrect input
     270: invokevirtual #77                 // Method java/lang/Object.toString:()Ljava/lang/String;
     273: invokespecial #80                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     276: athrow
     277: astore        8
     279: iconst_0
     280: istore        9
     282: aload         7
     284: invokestatic  #86                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     287: istore        10
     289: iload         9
     291: iload         10
     293: if_icmpge     31
     296: aload_1
     297: invokestatic  #92                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     300: checkcast     #15                 // class Cell
     303: aload         8
     305: invokevirtual #96                 // Method Cell.move:(LCell;)V
     308: iconst_1
     309: istore        11
     311: aload_1
     312: invokeinterface #99,  1           // InterfaceMethod java/util/List.size:()I
     317: istore        12
     319: iload         11
     321: iload         12
     323: if_icmpge     389
     326: aload_1
     327: iload         11
     329: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     334: checkcast     #15                 // class Cell
     337: aload_1
     338: iload         11
     340: iconst_1
     341: isub
     342: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     347: checkcast     #15                 // class Cell
     350: invokevirtual #103                // Method Cell.isAttached:(LCell;)Z
     353: ifne          383
     356: aload_1
     357: iload         11
     359: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     364: checkcast     #15                 // class Cell
     367: aload_1
     368: iload         11
     370: iconst_1
     371: isub
     372: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     377: checkcast     #15                 // class Cell
     380: invokevirtual #106                // Method Cell.follow:(LCell;)V
     383: iinc          11, 1
     386: goto          319
     389: aload_2
     390: aload_1
     391: invokestatic  #109                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     394: checkcast     #15                 // class Cell
     397: iconst_0
     398: iconst_0
     399: iconst_3
     400: aconst_null
     401: invokestatic  #113                // Method Cell.copy$default:(LCell;IIILjava/lang/Object;)LCell;
     404: invokevirtual #22                 // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
     407: pop
     408: iinc          9, 1
     411: goto          289
     414: aload_2
     415: invokevirtual #114                // Method java/util/HashSet.size:()I
     418: ireturn

  public static final void main();
    Code:
       0: ldc           #130                // String Day09_test
       2: invokestatic  #136                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #140                // Method main$part1:(Ljava/util/List;)I
      10: bipush        13
      12: if_icmpne     19
      15: iconst_1
      16: goto          20
      19: iconst_0
      20: ifne          33
      23: new           #71                 // class java/lang/IllegalStateException
      26: dup
      27: ldc           #142                // String Check failed.
      29: invokespecial #80                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      32: athrow
      33: aload_0
      34: invokestatic  #145                // Method main$part2:(Ljava/util/List;)I
      37: iconst_1
      38: if_icmpne     45
      41: iconst_1
      42: goto          46
      45: iconst_0
      46: ifne          59
      49: new           #71                 // class java/lang/IllegalStateException
      52: dup
      53: ldc           #142                // String Check failed.
      55: invokespecial #80                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      58: athrow
      59: ldc           #147                // String Day09
      61: invokestatic  #136                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      64: astore_1
      65: aload_1
      66: invokestatic  #140                // Method main$part1:(Ljava/util/List;)I
      69: istore_2
      70: getstatic     #153                // Field java/lang/System.out:Ljava/io/PrintStream;
      73: iload_2
      74: invokevirtual #159                // Method java/io/PrintStream.println:(I)V
      77: aload_1
      78: invokestatic  #145                // Method main$part2:(Ljava/util/List;)I
      81: istore_2
      82: getstatic     #153                // Field java/lang/System.out:Ljava/io/PrintStream;
      85: iload_2
      86: invokevirtual #159                // Method java/io/PrintStream.println:(I)V
      89: return

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: iconst_2
       2: istore_1
       3: astore        7
       5: new           #169                // class java/util/ArrayList
       8: dup
       9: iload_1
      10: invokespecial #171                // Method java/util/ArrayList."<init>":(I)V
      13: astore_2
      14: iconst_0
      15: istore_3
      16: iload_3
      17: iload_1
      18: if_icmpge     58
      21: iload_3
      22: istore        4
      24: aload_2
      25: iload         4
      27: istore        5
      29: astore        8
      31: iconst_0
      32: istore        6
      34: new           #15                 // class Cell
      37: dup
      38: iconst_0
      39: iconst_0
      40: iconst_3
      41: aconst_null
      42: invokespecial #18                 // Method Cell."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      45: aload         8
      47: swap
      48: invokevirtual #172                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      51: pop
      52: iinc          3, 1
      55: goto          16
      58: aload_2
      59: checkcast     #24                 // class java/util/List
      62: aload         7
      64: swap
      65: invokestatic  #174                // Method moveTheRope:(Ljava/util/List;Ljava/util/List;)I
      68: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: bipush        10
       3: istore_1
       4: astore        7
       6: new           #169                // class java/util/ArrayList
       9: dup
      10: iload_1
      11: invokespecial #171                // Method java/util/ArrayList."<init>":(I)V
      14: astore_2
      15: iconst_0
      16: istore_3
      17: iload_3
      18: iload_1
      19: if_icmpge     59
      22: iload_3
      23: istore        4
      25: aload_2
      26: iload         4
      28: istore        5
      30: astore        8
      32: iconst_0
      33: istore        6
      35: new           #15                 // class Cell
      38: dup
      39: iconst_0
      40: iconst_0
      41: iconst_3
      42: aconst_null
      43: invokespecial #18                 // Method Cell."<init>":(IIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      46: aload         8
      48: swap
      49: invokevirtual #172                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      52: pop
      53: iinc          3, 1
      56: goto          17
      59: aload_2
      60: checkcast     #24                 // class java/util/List
      63: aload         7
      65: swap
      66: invokestatic  #174                // Method moveTheRope:(Ljava/util/List;Ljava/util/List;)I
      69: ireturn
}


private fun getGrid(input: List<String>) = input.map { it.map(Char::digitToInt).toTypedArray() }.toTypedArray()

private fun observeLines(grid: Array<Array<Int>>, res: Array<BooleanArray>, lineInds: IntRange, rowInds: IntProgression) {
    val maxRowInd = if (rowInds.isRange()) 0 else grid.first().size - 1

    for (i in lineInds) {
        var max = grid[i + 1][maxRowInd]
        for (j in rowInds) {
            if (grid[i + 1][j + 1] > max) {
                res[i][j] = true
                max = grid[i + 1][j + 1]
            }
        }
    }

    if (rowInds.isRange()) observeLines(grid, res, lineInds, rowInds.reversed())
}

private fun observeRows(grid: Array<Array<Int>>, res: Array<BooleanArray>, lineInds: IntProgression, rowInds: IntRange) {
    val maxLineInd = if (lineInds.isRange()) 0 else grid.size - 1

    for (j in rowInds) {
        var max = grid[maxLineInd][j + 1]
        for (i in lineInds) {
            if (grid[i + 1][j + 1] > max) {
                res[i][j] = true
                max = grid[i + 1][j + 1]
            }
        }
    }

    if (lineInds.isRange()) observeRows(grid, res, lineInds.reversed(), rowInds)
}

private fun scenicScore(grid: Array<Array<Int>>, spot: Pair<Int, Int>) =
    neighbours().map { observeTree(grid, spot, it) }.reduce(Int::times)

private fun observeTree(grid: Array<Array<Int>>, spot: Pair<Int, Int>, shift: Pair<Int, Int>): Int {
    var dist = 0
    var indexes = spot + shift
    while (indexes.first in grid.indices && indexes.second in grid.first().indices) {
        dist++

        if (grid[indexes.first][indexes.second] >= grid[spot.first][spot.second]) break

        indexes += shift
    }

    return dist
}

fun main() {
    fun part1(input: List<String>): Int {
        val grid = getGrid(input)
        val n = grid.size
        val m = grid.first().size
        val res = Array(n - 2) { BooleanArray(m - 2) { false } }

        observeLines(grid, res, res.indices, res.first().indices)
        observeRows(grid, res, res.indices, res.first().indices)

        return res.sumOf { it.count { e -> e } } + 2 * (n + m - 2)
    }

    fun part2(input: List<String>): Int {
        val grid = getGrid(input)
        val res = Array(grid.size - 2) { IntArray(grid.first().size - 2) { 0 } }

        for (i in res.indices) {
            for (j in res.indices) {
                res[i][j] = scenicScore(grid, i + 1 to j + 1)
            }
        }

        return res.maxOf { it.max() }
    }

    // test if implementation meets criteria from the description, like:
    val testInput = readInput("Day08_test")
    check(part1(testInput) == 21)
    check(part2(testInput) == 8)

    val input = readInput("Day08")
    println(part1(input))
    println(part2(input))
}

Compiled from "Day08.kt"
public final class Day08Kt {
  private static final java.lang.Integer[][] getGrid(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #9                  // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #11                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #17                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #21                 // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #23                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          213
      48: aload         6
      50: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #39                 // class java/lang/String
      64: astore        8
      66: astore        20
      68: iconst_0
      69: istore        9
      71: aload         8
      73: checkcast     #41                 // class java/lang/CharSequence
      76: astore        10
      78: iconst_0
      79: istore        11
      81: aload         10
      83: astore        12
      85: new           #11                 // class java/util/ArrayList
      88: dup
      89: aload         10
      91: invokeinterface #45,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      96: invokespecial #21                 // Method java/util/ArrayList."<init>":(I)V
      99: checkcast     #23                 // class java/util/Collection
     102: astore        13
     104: iconst_0
     105: istore        14
     107: iconst_0
     108: istore        15
     110: iload         15
     112: aload         12
     114: invokeinterface #45,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     119: if_icmpge     167
     122: aload         12
     124: iload         15
     126: invokeinterface #49,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     131: istore        16
     133: aload         13
     135: iload         16
     137: istore        17
     139: astore        18
     141: iconst_0
     142: istore        19
     144: iload         17
     146: invokestatic  #55                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     149: invokestatic  #61                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     152: aload         18
     154: swap
     155: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     160: pop
     161: iinc          15, 1
     164: goto          110
     167: aload         13
     169: checkcast     #67                 // class java/util/List
     172: nop
     173: checkcast     #23                 // class java/util/Collection
     176: astore        10
     178: nop
     179: iconst_0
     180: istore        11
     182: aload         10
     184: astore        12
     186: aload         12
     188: iconst_0
     189: anewarray     #57                 // class java/lang/Integer
     192: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     197: checkcast     #73                 // class "[Ljava/lang/Integer;"
     200: nop
     201: aload         20
     203: swap
     204: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     209: pop
     210: goto          38
     213: aload         4
     215: checkcast     #67                 // class java/util/List
     218: nop
     219: checkcast     #23                 // class java/util/Collection
     222: astore_1
     223: nop
     224: iconst_0
     225: istore_2
     226: aload_1
     227: astore_3
     228: aload_3
     229: iconst_0
     230: anewarray     #73                 // class "[Ljava/lang/Integer;"
     233: invokeinterface #71,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     238: checkcast     #75                 // class "[[Ljava/lang/Integer;"
     241: areturn

  private static final void observeLines(java.lang.Integer[][], boolean[][], kotlin.ranges.IntRange, kotlin.ranges.IntProgression);
    Code:
       0: aload_3
       1: invokestatic  #105                // Method UtilsKt.isRange:(Lkotlin/ranges/IntProgression;)Z
       4: ifeq          11
       7: iconst_0
       8: goto          24
      11: aload_0
      12: checkcast     #107                // class "[Ljava/lang/Object;"
      15: invokestatic  #113                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      18: checkcast     #107                // class "[Ljava/lang/Object;"
      21: arraylength
      22: iconst_1
      23: isub
      24: istore        4
      26: aload_2
      27: invokevirtual #118                // Method kotlin/ranges/IntRange.getFirst:()I
      30: istore        5
      32: aload_2
      33: invokevirtual #121                // Method kotlin/ranges/IntRange.getLast:()I
      36: istore        6
      38: iload         5
      40: iload         6
      42: if_icmpgt     174
      45: aload_0
      46: iload         5
      48: iconst_1
      49: iadd
      50: aaload
      51: iload         4
      53: aaload
      54: invokevirtual #124                // Method java/lang/Integer.intValue:()I
      57: istore        7
      59: aload_3
      60: invokevirtual #127                // Method kotlin/ranges/IntProgression.getFirst:()I
      63: istore        8
      65: aload_3
      66: invokevirtual #128                // Method kotlin/ranges/IntProgression.getLast:()I
      69: istore        9
      71: aload_3
      72: invokevirtual #131                // Method kotlin/ranges/IntProgression.getStep:()I
      75: istore        10
      77: iload         10
      79: ifle          89
      82: iload         8
      84: iload         9
      86: if_icmple     101
      89: iload         10
      91: ifge          161
      94: iload         9
      96: iload         8
      98: if_icmpgt     161
     101: aload_0
     102: iload         5
     104: iconst_1
     105: iadd
     106: aaload
     107: iload         8
     109: iconst_1
     110: iadd
     111: aaload
     112: invokevirtual #124                // Method java/lang/Integer.intValue:()I
     115: iload         7
     117: if_icmple     144
     120: aload_1
     121: iload         5
     123: aaload
     124: iload         8
     126: iconst_1
     127: bastore
     128: aload_0
     129: iload         5
     131: iconst_1
     132: iadd
     133: aaload
     134: iload         8
     136: iconst_1
     137: iadd
     138: aaload
     139: invokevirtual #124                // Method java/lang/Integer.intValue:()I
     142: istore        7
     144: iload         8
     146: iload         9
     148: if_icmpeq     161
     151: iload         8
     153: iload         10
     155: iadd
     156: istore        8
     158: goto          101
     161: iload         5
     163: iload         6
     165: if_icmpeq     174
     168: iinc          5, 1
     171: goto          45
     174: aload_3
     175: invokestatic  #105                // Method UtilsKt.isRange:(Lkotlin/ranges/IntProgression;)Z
     178: ifeq          191
     181: aload_0
     182: aload_1
     183: aload_2
     184: aload_3
     185: invokestatic  #137                // Method kotlin/ranges/RangesKt.reversed:(Lkotlin/ranges/IntProgression;)Lkotlin/ranges/IntProgression;
     188: invokestatic  #139                // Method observeLines:([[Ljava/lang/Integer;[[ZLkotlin/ranges/IntRange;Lkotlin/ranges/IntProgression;)V
     191: return

  private static final void observeRows(java.lang.Integer[][], boolean[][], kotlin.ranges.IntProgression, kotlin.ranges.IntRange);
    Code:
       0: aload_2
       1: invokestatic  #105                // Method UtilsKt.isRange:(Lkotlin/ranges/IntProgression;)Z
       4: ifeq          11
       7: iconst_0
       8: goto          18
      11: aload_0
      12: checkcast     #107                // class "[Ljava/lang/Object;"
      15: arraylength
      16: iconst_1
      17: isub
      18: istore        4
      20: aload_3
      21: invokevirtual #118                // Method kotlin/ranges/IntRange.getFirst:()I
      24: istore        5
      26: aload_3
      27: invokevirtual #121                // Method kotlin/ranges/IntRange.getLast:()I
      30: istore        6
      32: iload         5
      34: iload         6
      36: if_icmpgt     168
      39: aload_0
      40: iload         4
      42: aaload
      43: iload         5
      45: iconst_1
      46: iadd
      47: aaload
      48: invokevirtual #124                // Method java/lang/Integer.intValue:()I
      51: istore        7
      53: aload_2
      54: invokevirtual #127                // Method kotlin/ranges/IntProgression.getFirst:()I
      57: istore        8
      59: aload_2
      60: invokevirtual #128                // Method kotlin/ranges/IntProgression.getLast:()I
      63: istore        9
      65: aload_2
      66: invokevirtual #131                // Method kotlin/ranges/IntProgression.getStep:()I
      69: istore        10
      71: iload         10
      73: ifle          83
      76: iload         8
      78: iload         9
      80: if_icmple     95
      83: iload         10
      85: ifge          155
      88: iload         9
      90: iload         8
      92: if_icmpgt     155
      95: aload_0
      96: iload         8
      98: iconst_1
      99: iadd
     100: aaload
     101: iload         5
     103: iconst_1
     104: iadd
     105: aaload
     106: invokevirtual #124                // Method java/lang/Integer.intValue:()I
     109: iload         7
     111: if_icmple     138
     114: aload_1
     115: iload         8
     117: aaload
     118: iload         5
     120: iconst_1
     121: bastore
     122: aload_0
     123: iload         8
     125: iconst_1
     126: iadd
     127: aaload
     128: iload         5
     130: iconst_1
     131: iadd
     132: aaload
     133: invokevirtual #124                // Method java/lang/Integer.intValue:()I
     136: istore        7
     138: iload         8
     140: iload         9
     142: if_icmpeq     155
     145: iload         8
     147: iload         10
     149: iadd
     150: istore        8
     152: goto          95
     155: iload         5
     157: iload         6
     159: if_icmpeq     168
     162: iinc          5, 1
     165: goto          39
     168: aload_2
     169: invokestatic  #105                // Method UtilsKt.isRange:(Lkotlin/ranges/IntProgression;)Z
     172: ifeq          185
     175: aload_0
     176: aload_1
     177: aload_2
     178: invokestatic  #137                // Method kotlin/ranges/RangesKt.reversed:(Lkotlin/ranges/IntProgression;)Lkotlin/ranges/IntProgression;
     181: aload_3
     182: invokestatic  #155                // Method observeRows:([[Ljava/lang/Integer;[[ZLkotlin/ranges/IntProgression;Lkotlin/ranges/IntRange;)V
     185: return

  private static final int scenicScore(java.lang.Integer[][], kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: invokestatic  #163                // Method UtilsKt.neighbours:()Ljava/util/List;
       3: checkcast     #9                  // class java/lang/Iterable
       6: astore_2
       7: iconst_0
       8: istore_3
       9: aload_2
      10: astore        4
      12: new           #11                 // class java/util/ArrayList
      15: dup
      16: aload_2
      17: bipush        10
      19: invokestatic  #17                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      22: invokespecial #21                 // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #23                 // class java/util/Collection
      28: astore        5
      30: iconst_0
      31: istore        6
      33: aload         4
      35: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        7
      42: aload         7
      44: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          97
      52: aload         7
      54: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        8
      61: aload         5
      63: aload         8
      65: checkcast     #165                // class kotlin/Pair
      68: astore        9
      70: astore        11
      72: iconst_0
      73: istore        10
      75: aload_0
      76: aload_1
      77: aload         9
      79: invokestatic  #169                // Method observeTree:([[Ljava/lang/Integer;Lkotlin/Pair;Lkotlin/Pair;)I
      82: invokestatic  #61                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: aload         11
      87: swap
      88: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: goto          42
      97: aload         5
      99: checkcast     #67                 // class java/util/List
     102: nop
     103: checkcast     #9                  // class java/lang/Iterable
     106: astore_2
     107: nop
     108: iconst_0
     109: istore_3
     110: aload_2
     111: invokeinterface #27,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        4
     118: aload         4
     120: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifne          138
     128: new           #171                // class java/lang/UnsupportedOperationException
     131: dup
     132: ldc           #173                // String Empty collection can\'t be reduced.
     134: invokespecial #176                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     137: athrow
     138: aload         4
     140: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     145: astore        5
     147: aload         4
     149: invokeinterface #33,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          198
     157: aload         5
     159: aload         4
     161: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     166: checkcast     #178                // class java/lang/Number
     169: invokevirtual #179                // Method java/lang/Number.intValue:()I
     172: istore        6
     174: checkcast     #178                // class java/lang/Number
     177: invokevirtual #179                // Method java/lang/Number.intValue:()I
     180: istore        7
     182: iconst_0
     183: istore        8
     185: iload         7
     187: iload         6
     189: imul
     190: invokestatic  #61                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     193: astore        5
     195: goto          147
     198: aload         5
     200: checkcast     #178                // class java/lang/Number
     203: invokevirtual #179                // Method java/lang/Number.intValue:()I
     206: ireturn

  private static final int observeTree(java.lang.Integer[][], kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: iconst_0
       1: istore_3
       2: aload_1
       3: aload_2
       4: invokestatic  #194                // Method UtilsKt.plus:(Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
       7: astore        4
       9: aload_0
      10: checkcast     #107                // class "[Ljava/lang/Object;"
      13: arraylength
      14: istore        5
      16: aload         4
      18: invokevirtual #196                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      21: checkcast     #178                // class java/lang/Number
      24: invokevirtual #179                // Method java/lang/Number.intValue:()I
      27: istore        6
      29: iconst_0
      30: iload         6
      32: if_icmpgt     50
      35: iload         6
      37: iload         5
      39: if_icmpge     46
      42: iconst_1
      43: goto          51
      46: iconst_0
      47: goto          51
      50: iconst_0
      51: ifeq          176
      54: aload_0
      55: checkcast     #107                // class "[Ljava/lang/Object;"
      58: invokestatic  #113                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      61: checkcast     #107                // class "[Ljava/lang/Object;"
      64: arraylength
      65: istore        5
      67: aload         4
      69: invokevirtual #199                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      72: checkcast     #178                // class java/lang/Number
      75: invokevirtual #179                // Method java/lang/Number.intValue:()I
      78: istore        6
      80: iconst_0
      81: iload         6
      83: if_icmpgt     101
      86: iload         6
      88: iload         5
      90: if_icmpge     97
      93: iconst_1
      94: goto          102
      97: iconst_0
      98: goto          102
     101: iconst_0
     102: ifeq          176
     105: iinc          3, 1
     108: aload_0
     109: aload         4
     111: invokevirtual #196                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     114: checkcast     #178                // class java/lang/Number
     117: invokevirtual #179                // Method java/lang/Number.intValue:()I
     120: aaload
     121: aload         4
     123: invokevirtual #199                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     126: checkcast     #178                // class java/lang/Number
     129: invokevirtual #179                // Method java/lang/Number.intValue:()I
     132: aaload
     133: invokevirtual #124                // Method java/lang/Integer.intValue:()I
     136: aload_0
     137: aload_1
     138: invokevirtual #196                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     141: checkcast     #178                // class java/lang/Number
     144: invokevirtual #179                // Method java/lang/Number.intValue:()I
     147: aaload
     148: aload_1
     149: invokevirtual #199                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     152: checkcast     #178                // class java/lang/Number
     155: invokevirtual #179                // Method java/lang/Number.intValue:()I
     158: aaload
     159: invokevirtual #124                // Method java/lang/Integer.intValue:()I
     162: if_icmpge     176
     165: aload         4
     167: aload_2
     168: invokestatic  #194                // Method UtilsKt.plus:(Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
     171: astore        4
     173: goto          9
     176: iload_3
     177: ireturn

  public static final void main();
    Code:
       0: ldc           #206                // String Day08_test
       2: invokestatic  #210                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #214                // Method main$part1:(Ljava/util/List;)I
      10: bipush        21
      12: if_icmpne     19
      15: iconst_1
      16: goto          20
      19: iconst_0
      20: ifne          33
      23: new           #216                // class java/lang/IllegalStateException
      26: dup
      27: ldc           #218                // String Check failed.
      29: invokespecial #219                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      32: athrow
      33: aload_0
      34: invokestatic  #222                // Method main$part2:(Ljava/util/List;)I
      37: bipush        8
      39: if_icmpne     46
      42: iconst_1
      43: goto          47
      46: iconst_0
      47: ifne          60
      50: new           #216                // class java/lang/IllegalStateException
      53: dup
      54: ldc           #218                // String Check failed.
      56: invokespecial #219                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      59: athrow
      60: ldc           #224                // String Day08
      62: invokestatic  #210                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      65: astore_1
      66: aload_1
      67: invokestatic  #214                // Method main$part1:(Ljava/util/List;)I
      70: istore_2
      71: getstatic     #230                // Field java/lang/System.out:Ljava/io/PrintStream;
      74: iload_2
      75: invokevirtual #235                // Method java/io/PrintStream.println:(I)V
      78: aload_1
      79: invokestatic  #222                // Method main$part2:(Ljava/util/List;)I
      82: istore_2
      83: getstatic     #230                // Field java/lang/System.out:Ljava/io/PrintStream;
      86: iload_2
      87: invokevirtual #235                // Method java/io/PrintStream.println:(I)V
      90: return

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #244                // Method getGrid:(Ljava/util/List;)[[Ljava/lang/Integer;
       4: astore_1
       5: aload_1
       6: checkcast     #107                // class "[Ljava/lang/Object;"
       9: arraylength
      10: istore_2
      11: aload_1
      12: checkcast     #107                // class "[Ljava/lang/Object;"
      15: invokestatic  #113                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      18: checkcast     #107                // class "[Ljava/lang/Object;"
      21: arraylength
      22: istore_3
      23: iconst_0
      24: istore        5
      26: iload_2
      27: iconst_2
      28: isub
      29: istore        6
      31: iload         6
      33: anewarray     #246                // class "[Z"
      36: astore        7
      38: iload         5
      40: iload         6
      42: if_icmpge     107
      45: iload         5
      47: istore        8
      49: aload         7
      51: iload         8
      53: iconst_0
      54: istore        9
      56: iload_3
      57: iconst_2
      58: isub
      59: istore        10
      61: iload         10
      63: newarray       boolean
      65: astore        11
      67: istore        21
      69: astore        20
      71: iload         9
      73: iload         10
      75: if_icmpge     94
      78: iload         9
      80: istore        12
      82: aload         11
      84: iload         12
      86: iconst_0
      87: bastore
      88: iinc          9, 1
      91: goto          71
      94: aload         20
      96: iload         21
      98: aload         11
     100: aastore
     101: iinc          5, 1
     104: goto          38
     107: aload         7
     109: astore        4
     111: aload_1
     112: aload         4
     114: aload         4
     116: checkcast     #107                // class "[Ljava/lang/Object;"
     119: invokestatic  #250                // Method kotlin/collections/ArraysKt.getIndices:([Ljava/lang/Object;)Lkotlin/ranges/IntRange;
     122: aload         4
     124: checkcast     #107                // class "[Ljava/lang/Object;"
     127: invokestatic  #113                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
     130: checkcast     #246                // class "[Z"
     133: invokestatic  #253                // Method kotlin/collections/ArraysKt.getIndices:([Z)Lkotlin/ranges/IntRange;
     136: checkcast     #126                // class kotlin/ranges/IntProgression
     139: invokestatic  #139                // Method observeLines:([[Ljava/lang/Integer;[[ZLkotlin/ranges/IntRange;Lkotlin/ranges/IntProgression;)V
     142: aload_1
     143: aload         4
     145: aload         4
     147: checkcast     #107                // class "[Ljava/lang/Object;"
     150: invokestatic  #250                // Method kotlin/collections/ArraysKt.getIndices:([Ljava/lang/Object;)Lkotlin/ranges/IntRange;
     153: checkcast     #126                // class kotlin/ranges/IntProgression
     156: aload         4
     158: checkcast     #107                // class "[Ljava/lang/Object;"
     161: invokestatic  #113                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
     164: checkcast     #246                // class "[Z"
     167: invokestatic  #253                // Method kotlin/collections/ArraysKt.getIndices:([Z)Lkotlin/ranges/IntRange;
     170: invokestatic  #155                // Method observeRows:([[Ljava/lang/Integer;[[ZLkotlin/ranges/IntProgression;Lkotlin/ranges/IntRange;)V
     173: aload         4
     175: checkcast     #107                // class "[Ljava/lang/Object;"
     178: astore        5
     180: iconst_0
     181: istore        6
     183: iconst_0
     184: istore        7
     186: aload         5
     188: arraylength
     189: istore        8
     191: iload         7
     193: iload         8
     195: if_icmpge     290
     198: aload         5
     200: iload         7
     202: aaload
     203: astore        9
     205: iload         6
     207: aload         9
     209: checkcast     #246                // class "[Z"
     212: astore        10
     214: istore        20
     216: iconst_0
     217: istore        11
     219: aload         10
     221: astore        12
     223: iconst_0
     224: istore        13
     226: iconst_0
     227: istore        14
     229: iconst_0
     230: istore        15
     232: aload         12
     234: arraylength
     235: istore        16
     237: iload         15
     239: iload         16
     241: if_icmpge     272
     244: aload         12
     246: iload         15
     248: baload
     249: istore        17
     251: iload         17
     253: istore        18
     255: iconst_0
     256: istore        19
     258: iload         18
     260: ifeq          266
     263: iinc          14, 1
     266: iinc          15, 1
     269: goto          237
     272: iload         14
     274: nop
     275: istore        21
     277: iload         20
     279: iload         21
     281: iadd
     282: istore        6
     284: iinc          7, 1
     287: goto          191
     290: iload         6
     292: iconst_2
     293: iload_2
     294: iload_3
     295: iadd
     296: iconst_2
     297: isub
     298: imul
     299: iadd
     300: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #244                // Method getGrid:(Ljava/util/List;)[[Ljava/lang/Integer;
       4: astore_1
       5: iconst_0
       6: istore_3
       7: aload_1
       8: checkcast     #107                // class "[Ljava/lang/Object;"
      11: arraylength
      12: iconst_2
      13: isub
      14: istore        4
      16: iload         4
      18: anewarray     #265                // class "[I"
      21: astore        5
      23: iload_3
      24: iload         4
      26: if_icmpge     100
      29: iload_3
      30: istore        6
      32: aload         5
      34: iload         6
      36: iconst_0
      37: istore        7
      39: aload_1
      40: checkcast     #107                // class "[Ljava/lang/Object;"
      43: invokestatic  #113                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      46: checkcast     #107                // class "[Ljava/lang/Object;"
      49: arraylength
      50: iconst_2
      51: isub
      52: istore        8
      54: iload         8
      56: newarray       int
      58: astore        9
      60: istore        12
      62: astore        11
      64: iload         7
      66: iload         8
      68: if_icmpge     87
      71: iload         7
      73: istore        10
      75: aload         9
      77: iload         10
      79: iconst_0
      80: iastore
      81: iinc          7, 1
      84: goto          64
      87: aload         11
      89: iload         12
      91: aload         9
      93: aastore
      94: iinc          3, 1
      97: goto          23
     100: aload         5
     102: astore_2
     103: iconst_0
     104: istore_3
     105: aload_2
     106: checkcast     #107                // class "[Ljava/lang/Object;"
     109: arraylength
     110: istore        4
     112: iload_3
     113: iload         4
     115: if_icmpge     173
     118: iconst_0
     119: istore        5
     121: aload_2
     122: checkcast     #107                // class "[Ljava/lang/Object;"
     125: arraylength
     126: istore        6
     128: iload         5
     130: iload         6
     132: if_icmpge     167
     135: aload_2
     136: iload_3
     137: aaload
     138: iload         5
     140: aload_1
     141: iload_3
     142: iconst_1
     143: iadd
     144: invokestatic  #61                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: iload         5
     149: iconst_1
     150: iadd
     151: invokestatic  #61                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: invokestatic  #271                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     157: invokestatic  #273                // Method scenicScore:([[Ljava/lang/Integer;Lkotlin/Pair;)I
     160: iastore
     161: iinc          5, 1
     164: goto          128
     167: iinc          3, 1
     170: goto          112
     173: aload_2
     174: checkcast     #107                // class "[Ljava/lang/Object;"
     177: astore_3
     178: aload_3
     179: arraylength
     180: ifne          187
     183: iconst_1
     184: goto          188
     187: iconst_0
     188: ifeq          199
     191: new           #275                // class java/util/NoSuchElementException
     194: dup
     195: invokespecial #277                // Method java/util/NoSuchElementException."<init>":()V
     198: athrow
     199: aload_3
     200: iconst_0
     201: aaload
     202: checkcast     #265                // class "[I"
     205: astore        4
     207: iconst_0
     208: istore        5
     210: aload         4
     212: invokestatic  #281                // Method kotlin/collections/ArraysKt.maxOrThrow:([I)I
     215: istore        4
     217: iconst_1
     218: istore        5
     220: aload_3
     221: invokestatic  #285                // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     224: istore        6
     226: iload         5
     228: iload         6
     230: if_icmpgt     276
     233: aload_3
     234: iload         5
     236: aaload
     237: checkcast     #265                // class "[I"
     240: astore        7
     242: iconst_0
     243: istore        8
     245: aload         7
     247: invokestatic  #281                // Method kotlin/collections/ArraysKt.maxOrThrow:([I)I
     250: istore        7
     252: iload         4
     254: iload         7
     256: if_icmpge     263
     259: iload         7
     261: istore        4
     263: iload         5
     265: iload         6
     267: if_icmpeq     276
     270: iinc          5, 1
     273: goto          233
     276: iload         4
     278: ireturn
}


// Списки (стеки, очереди) I(1..n) и U(1..n) содержат результаты n измерений тока и напряжения на неизвестном
// сопротивлении R. Найти приближенное число R методом наименьших квадратов.

import kotlin.math.pow

// Create a class LeastSquaresR that takes two lists of measurements, currents, and voltages
class LeastSquaresR(private val currents: List<Double>, private val voltages: List<Double>) {

    // Check if the input lists have the same size
    init {
        require(currents.size == voltages.size) { "Currents and voltages lists must have the same size" }
    }

    // Implement a method that calculates the least squares approximation of R based on the input data
    fun calculateR(): Double {
        // Calculate the sum of the product of each current and voltage measurement
        val sumIU = currents.zip(voltages) { i, u -> i * u }.sum()

        // Calculate the sum of the square of each current measurement
        val sumISquared = currents.map { it.pow(2) }.sum()

        // Calculate the number of measurements
        val n = currents.size

        // Calculate the approximate value of the unknown resistance R using the least squares method
        val r = sumIU / sumISquared

        return r
    }
}

fun task2V1() {
    // Provide sample data: two lists of current and voltage measurements
    val currents = listOf(0.5, 1.0, 1.5, 2.0, 2.5)
    val voltages = listOf(1.0, 2.1, 3.1, 4.1, 5.0)

    // Create a LeastSquaresR object with the sample data
    val leastSquaresR = LeastSquaresR(currents, voltages)

    // Calculate the approximate value of the unknown resistance R
    val r = leastSquaresR.calculateR()

    // Print the result
    println("The approximate value of the unknown resistance R is: $r Ω")
}

Compiled from "Task2V1.kt"
public final class Task2V1Kt {
  public static final void task2V1();
    Code:
       0: iconst_5
       1: anewarray     #8                  // class java/lang/Double
       4: astore_1
       5: aload_1
       6: iconst_0
       7: ldc2_w        #9                  // double 0.5d
      10: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      13: aastore
      14: aload_1
      15: iconst_1
      16: dconst_1
      17: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      20: aastore
      21: aload_1
      22: iconst_2
      23: ldc2_w        #15                 // double 1.5d
      26: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      29: aastore
      30: aload_1
      31: iconst_3
      32: ldc2_w        #17                 // double 2.0d
      35: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      38: aastore
      39: aload_1
      40: iconst_4
      41: ldc2_w        #19                 // double 2.5d
      44: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      47: aastore
      48: aload_1
      49: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      52: astore_0
      53: iconst_5
      54: anewarray     #8                  // class java/lang/Double
      57: astore_2
      58: aload_2
      59: iconst_0
      60: dconst_1
      61: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      64: aastore
      65: aload_2
      66: iconst_1
      67: ldc2_w        #27                 // double 2.1d
      70: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      73: aastore
      74: aload_2
      75: iconst_2
      76: ldc2_w        #29                 // double 3.1d
      79: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      82: aastore
      83: aload_2
      84: iconst_3
      85: ldc2_w        #31                 // double 4.1d
      88: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      91: aastore
      92: aload_2
      93: iconst_4
      94: ldc2_w        #33                 // double 5.0d
      97: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     100: aastore
     101: aload_2
     102: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     105: astore_1
     106: new           #36                 // class LeastSquaresR
     109: dup
     110: aload_0
     111: aload_1
     112: invokespecial #40                 // Method LeastSquaresR."<init>":(Ljava/util/List;Ljava/util/List;)V
     115: astore_2
     116: aload_2
     117: invokevirtual #44                 // Method LeastSquaresR.calculateR:()D
     120: dstore_3
     121: new           #46                 // class java/lang/StringBuilder
     124: dup
     125: invokespecial #48                 // Method java/lang/StringBuilder."<init>":()V
     128: ldc           #50                 // String The approximate value of the unknown resistance R is:
     130: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     133: dload_3
     134: invokevirtual #57                 // Method java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder;
     137: ldc           #59                 // String  Ω
     139: invokevirtual #54                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     142: invokevirtual #63                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     145: getstatic     #69                 // Field java/lang/System.out:Ljava/io/PrintStream;
     148: swap
     149: invokevirtual #75                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     152: return
}


// В тексте нет слов, начинающихся одинаковыми буквами. Напечатать слова текста в таком порядке, чтобы последняя буква
// каждого слова совпадала с первой буквой последующего слова. Если все слова нельзя напечатать в таком порядке, найти
// такую цепочку, состоящую из наибольшего количества слов.

// The WordChainFinder class takes a list of words and finds the longest word chain
class WordChainFinder(private val words: List<String>) {

    // A recursive method to find a word chain given a current chain and a list of remaining words
    private fun findWordChain(currentChain: List<String>, remainingWords: List<String>): List<String> {
        // If there are no remaining words, return the current chain
        if (remainingWords.isEmpty()) {
            return currentChain
        }

        // Get the last letter of the last word in the current chain
        val lastLetter = currentChain.last().last()

        // Find the candidate words in the remaining words that start with the last letter of the current chain
        val candidates = remainingWords.filter { it.first() == lastLetter }

        // If there are no candidates, return the current chain
        if (candidates.isEmpty()) {
            return currentChain
        }

        // For each candidate word, extend the current chain with the candidate and remove it from the remaining words
        val chains = candidates.map { candidate ->
            val newRemainingWords = remainingWords.toMutableList().apply { remove(candidate) }
            findWordChain(currentChain + candidate, newRemainingWords)
        }

        // Return the longest chain found among the chains extended with the candidates
        return chains.maxByOrNull { it.size } ?: currentChain
    }

    // The findLongestWordChain method finds the longest word chain by starting a search from each word in the list
    fun findLongestWordChain(): List<String> {
        return words.map { word ->
            val remainingWords = words.toMutableList().apply { remove(word) }
            findWordChain(listOf(word), remainingWords)
        }.maxByOrNull { it.size } ?: emptyList()
    }
}

fun task1V3() {
    // Provide an example input text
    val text = "java android kotlin rust"

    // Split the input text into words
    val words = text.split(" ")

    // Create a WordChainFinder object with the list of words
    val wordChainFinder = WordChainFinder(words)

    // Call the findLongestWordChain method to find the longest chain of words
    val longestWordChain = wordChainFinder.findLongestWordChain()

    // Print the longest word chain to the console
    println("Longest word chain: ${longestWordChain.joinToString(", ")}")
}

Compiled from "Task1V3.kt"
public final class Task1V3Kt {
  public static final void task1V3();
    Code:
       0: ldc           #8                  // String java android kotlin rust
       2: astore_0
       3: aload_0
       4: checkcast     #10                 // class java/lang/CharSequence
       7: iconst_1
       8: anewarray     #12                 // class java/lang/String
      11: astore_2
      12: aload_2
      13: iconst_0
      14: ldc           #14                 // String
      16: aastore
      17: aload_2
      18: iconst_0
      19: iconst_0
      20: bipush        6
      22: aconst_null
      23: invokestatic  #20                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      26: astore_1
      27: new           #22                 // class WordChainFinder
      30: dup
      31: aload_1
      32: invokespecial #26                 // Method WordChainFinder."<init>":(Ljava/util/List;)V
      35: astore_2
      36: aload_2
      37: invokevirtual #30                 // Method WordChainFinder.findLongestWordChain:()Ljava/util/List;
      40: astore_3
      41: new           #32                 // class java/lang/StringBuilder
      44: dup
      45: invokespecial #34                 // Method java/lang/StringBuilder."<init>":()V
      48: ldc           #36                 // String Longest word chain:
      50: invokevirtual #40                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      53: aload_3
      54: checkcast     #42                 // class java/lang/Iterable
      57: ldc           #44                 // String ,
      59: checkcast     #10                 // class java/lang/CharSequence
      62: aconst_null
      63: aconst_null
      64: iconst_0
      65: aconst_null
      66: aconst_null
      67: bipush        62
      69: aconst_null
      70: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      73: invokevirtual #40                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      76: invokevirtual #54                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      79: getstatic     #60                 // Field java/lang/System.out:Ljava/io/PrintStream;
      82: swap
      83: invokevirtual #66                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      86: return
}


// https://codeforces.com/contest/1904/problem/D1

private fun String.splitWhitespace() = split("\\s+".toRegex())
private fun readInt(): Int = readln().toInt()
private fun readInts(): List<Int> = readln().splitWhitespace().map { it.toInt() }

fun canABecomeB(n: Int, a: MutableList<Int>, b: List<Int>): Boolean {
    // If any b[i] < a[a], return false
    if ((0..<n).any { i -> b[i] < a[i] }) {
        return false
    }

    for (g in 0..n) {
        for (i in 0..<n) {
            if (b[i] == g && a[i] < g) {
                // Find an l to the left
                var l = i
                while (l > 0 && a[l - 1] <= g && b[l - 1] >= g) {
                    l--
                }
                // Find r
                var r = i
                while (r < n - 1 && a[r + 1] <= g && b[r + 1] >= g) {
                    r++
                }
                if (!(l..r).any { j -> a[j] == g }) {
                    return false
                }
                for (j in l..r) {
                    a[j] = g
                }
            }
        }
    }
    return a == b
}

fun main() {
    val t = readInt()
    (0..<t).forEach { _ ->
        val n = readInt()
        val a = readInts().toMutableList()
        val b = readInts()

        // operation: Choose l and r, where 1 <= l <= r <= n
        // let x = max(a[l]..a[r])
        // Set all a[l]..a[r] to max

        // Output YES if a can become b with any number of operations
        // Output NO if not
        if (canABecomeB(n, a, b)) {
            println("YES")
        } else {
            println("NO")
        }
    }
}

Compiled from "D1.kt"
public final class D1Kt {
  private static final java.util.List<java.lang.String> splitWhitespace(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #9                  // class java/lang/CharSequence
       4: astore_1
       5: new           #11                 // class kotlin/text/Regex
       8: dup
       9: ldc           #13                 // String \\s+
      11: invokespecial #17                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      14: astore_2
      15: iconst_0
      16: istore_3
      17: aload_2
      18: aload_1
      19: iload_3
      20: invokevirtual #21                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      23: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #31                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: invokestatic  #37                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #31                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: invokestatic  #42                 // Method splitWhitespace:(Ljava/lang/String;)Ljava/util/List;
       6: checkcast     #44                 // class java/lang/Iterable
       9: astore_0
      10: iconst_0
      11: istore_1
      12: aload_0
      13: astore_2
      14: new           #46                 // class java/util/ArrayList
      17: dup
      18: aload_0
      19: bipush        10
      21: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      24: invokespecial #55                 // Method java/util/ArrayList."<init>":(I)V
      27: checkcast     #57                 // class java/util/Collection
      30: astore_3
      31: iconst_0
      32: istore        4
      34: aload_2
      35: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        5
      42: aload         5
      44: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          95
      52: aload         5
      54: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        6
      61: aload_3
      62: aload         6
      64: checkcast     #73                 // class java/lang/String
      67: astore        7
      69: astore        9
      71: iconst_0
      72: istore        8
      74: aload         7
      76: invokestatic  #37                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      79: nop
      80: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      83: aload         9
      85: swap
      86: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: goto          42
      95: aload_3
      96: checkcast     #83                 // class java/util/List
      99: nop
     100: areturn

  public static final boolean canABecomeB(int, java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #101                // String a
       3: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #109                // String b
       9: invokestatic  #107                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: iload_0
      14: invokestatic  #115                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      17: checkcast     #44                 // class java/lang/Iterable
      20: astore_3
      21: iconst_0
      22: istore        4
      24: aload_3
      25: instanceof    #57                 // class java/util/Collection
      28: ifeq          47
      31: aload_3
      32: checkcast     #57                 // class java/util/Collection
      35: invokeinterface #118,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      40: ifeq          47
      43: iconst_0
      44: goto          126
      47: aload_3
      48: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        5
      55: aload         5
      57: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          125
      65: aload         5
      67: checkcast     #120                // class kotlin/collections/IntIterator
      70: invokevirtual #123                // Method kotlin/collections/IntIterator.nextInt:()I
      73: istore        6
      75: iload         6
      77: istore        7
      79: iconst_0
      80: istore        8
      82: aload_2
      83: iload         7
      85: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      90: checkcast     #129                // class java/lang/Number
      93: invokevirtual #132                // Method java/lang/Number.intValue:()I
      96: aload_1
      97: iload         7
      99: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     104: checkcast     #129                // class java/lang/Number
     107: invokevirtual #132                // Method java/lang/Number.intValue:()I
     110: if_icmpge     117
     113: iconst_1
     114: goto          118
     117: iconst_0
     118: ifeq          55
     121: iconst_1
     122: goto          126
     125: iconst_0
     126: ifeq          131
     129: iconst_0
     130: ireturn
     131: iconst_0
     132: istore_3
     133: iload_3
     134: iload_0
     135: if_icmpgt     470
     138: iconst_0
     139: istore        4
     141: iload         4
     143: iload_0
     144: if_icmpge     459
     147: aload_2
     148: iload         4
     150: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     155: checkcast     #129                // class java/lang/Number
     158: invokevirtual #132                // Method java/lang/Number.intValue:()I
     161: iload_3
     162: if_icmpne     453
     165: aload_1
     166: iload         4
     168: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     173: checkcast     #129                // class java/lang/Number
     176: invokevirtual #132                // Method java/lang/Number.intValue:()I
     179: iload_3
     180: if_icmpge     453
     183: iload         4
     185: istore        5
     187: iload         5
     189: ifle          238
     192: aload_1
     193: iload         5
     195: iconst_1
     196: isub
     197: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     202: checkcast     #129                // class java/lang/Number
     205: invokevirtual #132                // Method java/lang/Number.intValue:()I
     208: iload_3
     209: if_icmpgt     238
     212: aload_2
     213: iload         5
     215: iconst_1
     216: isub
     217: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     222: checkcast     #129                // class java/lang/Number
     225: invokevirtual #132                // Method java/lang/Number.intValue:()I
     228: iload_3
     229: if_icmplt     238
     232: iinc          5, -1
     235: goto          187
     238: iload         4
     240: istore        6
     242: iload         6
     244: iload_0
     245: iconst_1
     246: isub
     247: if_icmpge     296
     250: aload_1
     251: iload         6
     253: iconst_1
     254: iadd
     255: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     260: checkcast     #129                // class java/lang/Number
     263: invokevirtual #132                // Method java/lang/Number.intValue:()I
     266: iload_3
     267: if_icmpgt     296
     270: aload_2
     271: iload         6
     273: iconst_1
     274: iadd
     275: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     280: checkcast     #129                // class java/lang/Number
     283: invokevirtual #132                // Method java/lang/Number.intValue:()I
     286: iload_3
     287: if_icmplt     296
     290: iinc          6, 1
     293: goto          242
     296: new           #134                // class kotlin/ranges/IntRange
     299: dup
     300: iload         5
     302: iload         6
     304: invokespecial #137                // Method kotlin/ranges/IntRange."<init>":(II)V
     307: checkcast     #44                 // class java/lang/Iterable
     310: astore        7
     312: iconst_0
     313: istore        8
     315: aload         7
     317: instanceof    #57                 // class java/util/Collection
     320: ifeq          340
     323: aload         7
     325: checkcast     #57                 // class java/util/Collection
     328: invokeinterface #118,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     333: ifeq          340
     336: iconst_0
     337: goto          407
     340: aload         7
     342: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     347: astore        9
     349: aload         9
     351: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     356: ifeq          406
     359: aload         9
     361: checkcast     #120                // class kotlin/collections/IntIterator
     364: invokevirtual #123                // Method kotlin/collections/IntIterator.nextInt:()I
     367: istore        10
     369: iload         10
     371: istore        11
     373: iconst_0
     374: istore        12
     376: aload_1
     377: iload         11
     379: invokeinterface #127,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     384: checkcast     #129                // class java/lang/Number
     387: invokevirtual #132                // Method java/lang/Number.intValue:()I
     390: iload_3
     391: if_icmpne     398
     394: iconst_1
     395: goto          399
     398: iconst_0
     399: ifeq          349
     402: iconst_1
     403: goto          407
     406: iconst_0
     407: ifne          412
     410: iconst_0
     411: ireturn
     412: iload         5
     414: istore        7
     416: iload         6
     418: istore        8
     420: iload         7
     422: iload         8
     424: if_icmpgt     453
     427: aload_1
     428: iload         7
     430: iload_3
     431: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     434: invokeinterface #141,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     439: pop
     440: iload         7
     442: iload         8
     444: if_icmpeq     453
     447: iinc          7, 1
     450: goto          427
     453: iinc          4, 1
     456: goto          141
     459: iload_3
     460: iload_0
     461: if_icmpeq     470
     464: iinc          3, 1
     467: goto          138
     470: aload_1
     471: aload_2
     472: invokestatic  #145                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     475: ireturn

  public static final void main();
    Code:
       0: invokestatic  #161                // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: iload_0
       6: invokestatic  #115                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       9: checkcast     #44                 // class java/lang/Iterable
      12: astore_1
      13: iconst_0
      14: istore_2
      15: aload_1
      16: invokeinterface #61,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      21: astore_3
      22: aload_3
      23: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      28: ifeq          102
      31: aload_3
      32: checkcast     #120                // class kotlin/collections/IntIterator
      35: invokevirtual #123                // Method kotlin/collections/IntIterator.nextInt:()I
      38: istore        4
      40: iconst_0
      41: istore        5
      43: invokestatic  #161                // Method readInt:()I
      46: istore        6
      48: invokestatic  #163                // Method readInts:()Ljava/util/List;
      51: checkcast     #57                 // class java/util/Collection
      54: invokestatic  #167                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      57: astore        7
      59: invokestatic  #163                // Method readInts:()Ljava/util/List;
      62: astore        8
      64: iload         6
      66: aload         7
      68: aload         8
      70: invokestatic  #169                // Method canABecomeB:(ILjava/util/List;Ljava/util/List;)Z
      73: ifeq          88
      76: ldc           #171                // String YES
      78: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
      81: swap
      82: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      85: goto          97
      88: ldc           #185                // String NO
      90: getstatic     #177                // Field java/lang/System.out:Ljava/io/PrintStream;
      93: swap
      94: invokevirtual #183                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      97: nop
      98: nop
      99: goto          22
     102: nop
     103: return

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


import kotlin.math.min

// https://codeforces.com/contest/1907/problem/C
private fun readInt(): Int = readln().toInt()

private fun solve(n: Int, s: String): Int {
    var min = n
    val checked = mutableSetOf(s)
    val q = ArrayDeque<String>()
    q.addFirst(s)
    while (q.isNotEmpty()) {
        val str = q.removeFirst()
        for (i in 0..<str.length - 1) {
            if (str[i] == str[i + 1]) {
                continue
            }

            // Remove i and i+1
            val newStrBuilder = StringBuilder()
            for (j in str.indices) {
                if (i != j && i + 1 != j) {
                    newStrBuilder.append(str[j])
                }
            }
            val newStr = newStrBuilder.toString()
            if (checked.contains(newStr)) {
                continue
            }

            min = min(newStr.length, min)
            if (min == 0) {
                break
            }

            q.addLast(newStr)
            checked.add(newStr)
            println("Check $newStr")
        }
    }

    return min
}

private fun testcase() {
    val n = readInt()
    val s = readln()
    val min = solve(n, s)
    println(min)
}

fun main() {
//    val min = solve(20000, "abacd".repeat(20000 / 5))
    val min = solve(2000, "abacd".repeat(2000 / 5))
    println(min)
    return
    val t = readInt()
    for (i in 0..<t) {
        testcase()
    }
}

Compiled from "C.kt"
public final class CKt {
  private static final int readInt();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: invokestatic  #18                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final int solve(int, java.lang.String);
    Code:
       0: iload_0
       1: istore_2
       2: iconst_1
       3: anewarray     #22                 // class java/lang/String
       6: astore        4
       8: aload         4
      10: iconst_0
      11: aload_1
      12: aastore
      13: aload         4
      15: invokestatic  #28                 // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      18: astore_3
      19: new           #30                 // class kotlin/collections/ArrayDeque
      22: dup
      23: invokespecial #34                 // Method kotlin/collections/ArrayDeque."<init>":()V
      26: astore        4
      28: aload         4
      30: aload_1
      31: invokevirtual #38                 // Method kotlin/collections/ArrayDeque.addFirst:(Ljava/lang/Object;)V
      34: aload         4
      36: checkcast     #40                 // class java/util/Collection
      39: invokeinterface #44,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      44: ifne          51
      47: iconst_1
      48: goto          52
      51: iconst_0
      52: ifeq          265
      55: aload         4
      57: invokevirtual #48                 // Method kotlin/collections/ArrayDeque.removeFirst:()Ljava/lang/Object;
      60: checkcast     #22                 // class java/lang/String
      63: astore        5
      65: iconst_0
      66: istore        6
      68: aload         5
      70: invokevirtual #51                 // Method java/lang/String.length:()I
      73: iconst_1
      74: isub
      75: istore        7
      77: iload         6
      79: iload         7
      81: if_icmpge     34
      84: aload         5
      86: iload         6
      88: invokevirtual #55                 // Method java/lang/String.charAt:(I)C
      91: aload         5
      93: iload         6
      95: iconst_1
      96: iadd
      97: invokevirtual #55                 // Method java/lang/String.charAt:(I)C
     100: if_icmpne     106
     103: goto          259
     106: new           #57                 // class java/lang/StringBuilder
     109: dup
     110: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     113: astore        8
     115: iconst_0
     116: istore        9
     118: aload         5
     120: checkcast     #60                 // class java/lang/CharSequence
     123: invokeinterface #61,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     128: istore        10
     130: iload         9
     132: iload         10
     134: if_icmpge     172
     137: iload         6
     139: iload         9
     141: if_icmpeq     166
     144: iload         6
     146: iconst_1
     147: iadd
     148: iload         9
     150: if_icmpeq     166
     153: aload         8
     155: aload         5
     157: iload         9
     159: invokevirtual #55                 // Method java/lang/String.charAt:(I)C
     162: invokevirtual #65                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     165: pop
     166: iinc          9, 1
     169: goto          130
     172: aload         8
     174: invokevirtual #68                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     177: dup
     178: ldc           #70                 // String toString(...)
     180: invokestatic  #76                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     183: astore        9
     185: aload_3
     186: aload         9
     188: invokeinterface #82,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     193: ifeq          199
     196: goto          259
     199: aload         9
     201: invokevirtual #51                 // Method java/lang/String.length:()I
     204: iload_2
     205: invokestatic  #88                 // Method java/lang/Math.min:(II)I
     208: istore_2
     209: iload_2
     210: ifne          216
     213: goto          34
     216: aload         4
     218: aload         9
     220: invokevirtual #91                 // Method kotlin/collections/ArrayDeque.addLast:(Ljava/lang/Object;)V
     223: aload_3
     224: aload         9
     226: invokeinterface #94,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     231: pop
     232: new           #57                 // class java/lang/StringBuilder
     235: dup
     236: invokespecial #58                 // Method java/lang/StringBuilder."<init>":()V
     239: ldc           #96                 // String Check
     241: invokevirtual #99                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     244: aload         9
     246: invokevirtual #99                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     249: invokevirtual #68                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     252: getstatic     #105                // Field java/lang/System.out:Ljava/io/PrintStream;
     255: swap
     256: invokevirtual #110                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     259: iinc          6, 1
     262: goto          77
     265: iload_2
     266: ireturn

  private static final void testcase();
    Code:
       0: invokestatic  #127                // Method readInt:()I
       3: istore_0
       4: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       7: astore_1
       8: iload_0
       9: aload_1
      10: invokestatic  #129                // Method solve:(ILjava/lang/String;)I
      13: istore_2
      14: getstatic     #105                // Field java/lang/System.out:Ljava/io/PrintStream;
      17: iload_2
      18: invokevirtual #132                // Method java/io/PrintStream.println:(I)V
      21: return

  public static final void main();
    Code:
       0: sipush        2000
       3: ldc           #135                // String abacd
       5: checkcast     #60                 // class java/lang/CharSequence
       8: sipush        400
      11: invokestatic  #141                // Method kotlin/text/StringsKt.repeat:(Ljava/lang/CharSequence;I)Ljava/lang/String;
      14: invokestatic  #129                // Method solve:(ILjava/lang/String;)I
      17: istore_0
      18: getstatic     #105                // Field java/lang/System.out:Ljava/io/PrintStream;
      21: iload_0
      22: invokevirtual #132                // Method java/io/PrintStream.println:(I)V
      25: return

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