import kotlin.math.abs
import kotlin.math.sign

fun main() {
    Rope.solve()
}

private object Rope {
    fun solve() {
        val moves = readInput()
        println("tail visited ${getTailPath(moves, 10).toSet().size}")
    }

    private fun readInput(): Sequence<Move> {
        return generateSequence(::readLine).map {
            val parts = it.split(" ")
            val direction = when (parts[0]) {
                "U" -> Direction.Up
                "D" -> Direction.Down
                "L" -> Direction.Left
                "R" -> Direction.Right
                else -> throw Error("Unexpected direction ${parts[0]}")
            }
            val length = parts[1].toInt(10)
            Move(direction, length)
        }
    }

    private fun getTailPath(moves: Sequence<Move>, ropeSize: Int): List<Pos> {
        var head = Pos(0, 0)
        var rope = Array<Pos>(ropeSize) { head }
        val path = mutableListOf<Pos>()
        moves.forEach {
            println("Move $it")
            for (i in 0 until it.length) {
                head = when (it.direction) {
                    Direction.Up -> Pos(head.x, head.y + 1)
                    Direction.Down -> Pos(head.x, head.y - 1)
                    Direction.Left -> Pos(head.x - 1, head.y)
                    Direction.Right -> Pos(head.x + 1, head.y)
                }
                var prev = head
                rope = Array<Pos>(ropeSize) { j ->
                    if (i == 0)
                        head
                    else {
                        val pos = nextTailPos(prev, rope[j])
                        prev = pos
                        pos
                    }
                }
                path.add(rope.last())
            }
        }
        return path
    }

    private fun nextTailPos(headPos: Pos, tailPos: Pos): Pos {
        val dx = headPos.x - tailPos.x
        val dy = headPos.y - tailPos.y
        if (abs(dx) > 1 || abs(dy) > 1) {
            var (x, y) = tailPos
            x += sign(dx.toDouble()).toInt()
            y += sign(dy.toDouble()).toInt()
            return Pos(x, y)
        }
        return tailPos
    }
}

private data class Pos(val x: Int, val y: Int)
private enum class Direction {
    Up,
    Down,
    Left,
    Right,
}

private data class Move(val direction: Direction, val length: Int)

Compiled from "Rope.kt"
final class Rope {
  public static final Rope INSTANCE;

  private Rope();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void solve();
    Code:
       0: aload_0
       1: invokespecial #15                 // Method readInput:()Lkotlin/sequences/Sequence;
       4: astore_1
       5: new           #17                 // class java/lang/StringBuilder
       8: dup
       9: invokespecial #18                 // Method java/lang/StringBuilder."<init>":()V
      12: ldc           #20                 // String tail visited
      14: invokevirtual #24                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      17: aload_0
      18: aload_1
      19: bipush        10
      21: invokespecial #28                 // Method getTailPath:(Lkotlin/sequences/Sequence;I)Ljava/util/List;
      24: checkcast     #30                 // class java/lang/Iterable
      27: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
      30: invokeinterface #42,  1           // InterfaceMethod java/util/Set.size:()I
      35: invokevirtual #45                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      38: invokevirtual #49                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      41: getstatic     #55                 // Field java/lang/System.out:Ljava/io/PrintStream;
      44: swap
      45: invokevirtual #61                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      48: return

  private final kotlin.sequences.Sequence<Move> readInput();
    Code:
       0: getstatic     #70                 // Field Rope$readInput$1.INSTANCE:LRope$readInput$1;
       3: checkcast     #72                 // class kotlin/jvm/functions/Function0
       6: invokestatic  #78                 // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
       9: invokedynamic #97,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      14: invokestatic  #101                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      17: areturn

  private final java.util.List<Pos> getTailPath(kotlin.sequences.Sequence<Move>, int);
    Code:
       0: aconst_null
       1: astore_3
       2: new           #104                // class Pos
       5: dup
       6: iconst_0
       7: iconst_0
       8: invokespecial #107                // Method Pos."<init>":(II)V
      11: astore_3
      12: aconst_null
      13: astore        4
      15: iconst_0
      16: istore        5
      18: iload_2
      19: anewarray     #104                // class Pos
      22: astore        6
      24: iload         5
      26: iload_2
      27: if_icmpge     46
      30: iload         5
      32: istore        7
      34: aload         6
      36: iload         7
      38: aload_3
      39: aastore
      40: iinc          5, 1
      43: goto          24
      46: aload         6
      48: astore        4
      50: new           #109                // class java/util/ArrayList
      53: dup
      54: invokespecial #110                // Method java/util/ArrayList."<init>":()V
      57: checkcast     #112                // class java/util/List
      60: astore        5
      62: aload_1
      63: astore        6
      65: iconst_0
      66: istore        7
      68: aload         6
      70: invokeinterface #118,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      75: astore        8
      77: aload         8
      79: invokeinterface #124,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      84: ifeq          375
      87: aload         8
      89: invokeinterface #128,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      94: astore        9
      96: aload         9
      98: checkcast     #130                // class Move
     101: astore        10
     103: iconst_0
     104: istore        11
     106: new           #17                 // class java/lang/StringBuilder
     109: dup
     110: invokespecial #18                 // Method java/lang/StringBuilder."<init>":()V
     113: ldc           #132                // String Move
     115: invokevirtual #24                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     118: aload         10
     120: invokevirtual #135                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     123: invokevirtual #49                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     126: getstatic     #55                 // Field java/lang/System.out:Ljava/io/PrintStream;
     129: swap
     130: invokevirtual #61                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     133: iconst_0
     134: istore        12
     136: aload         10
     138: invokevirtual #138                // Method Move.getLength:()I
     141: istore        13
     143: iload         12
     145: iload         13
     147: if_icmpge     370
     150: aload         10
     152: invokevirtual #142                // Method Move.getDirection:()LDirection;
     155: getstatic     #148                // Field Rope$WhenMappings.$EnumSwitchMapping$0:[I
     158: swap
     159: invokevirtual #153                // Method Direction.ordinal:()I
     162: iaload
     163: tableswitch   { // 1 to 4
                     1: 192
                     2: 212
                     3: 232
                     4: 252
               default: 272
          }
     192: new           #104                // class Pos
     195: dup
     196: aload_3
     197: invokevirtual #156                // Method Pos.getX:()I
     200: aload_3
     201: invokevirtual #159                // Method Pos.getY:()I
     204: iconst_1
     205: iadd
     206: invokespecial #107                // Method Pos."<init>":(II)V
     209: goto          280
     212: new           #104                // class Pos
     215: dup
     216: aload_3
     217: invokevirtual #156                // Method Pos.getX:()I
     220: aload_3
     221: invokevirtual #159                // Method Pos.getY:()I
     224: iconst_1
     225: isub
     226: invokespecial #107                // Method Pos."<init>":(II)V
     229: goto          280
     232: new           #104                // class Pos
     235: dup
     236: aload_3
     237: invokevirtual #156                // Method Pos.getX:()I
     240: iconst_1
     241: isub
     242: aload_3
     243: invokevirtual #159                // Method Pos.getY:()I
     246: invokespecial #107                // Method Pos."<init>":(II)V
     249: goto          280
     252: new           #104                // class Pos
     255: dup
     256: aload_3
     257: invokevirtual #156                // Method Pos.getX:()I
     260: iconst_1
     261: iadd
     262: aload_3
     263: invokevirtual #159                // Method Pos.getY:()I
     266: invokespecial #107                // Method Pos."<init>":(II)V
     269: goto          280
     272: new           #161                // class kotlin/NoWhenBranchMatchedException
     275: dup
     276: invokespecial #162                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     279: athrow
     280: astore_3
     281: aload_3
     282: astore        14
     284: iconst_0
     285: istore        15
     287: iload_2
     288: anewarray     #104                // class Pos
     291: astore        16
     293: iload         15
     295: iload_2
     296: if_icmpge     344
     299: iload         15
     301: istore        17
     303: aload         16
     305: iload         17
     307: iload         12
     309: ifne          316
     312: aload_3
     313: goto          337
     316: getstatic     #164                // Field INSTANCE:LRope;
     319: aload         14
     321: aload         4
     323: iload         17
     325: aaload
     326: invokespecial #168                // Method nextTailPos:(LPos;LPos;)LPos;
     329: astore        18
     331: aload         18
     333: astore        14
     335: aload         18
     337: aastore
     338: iinc          15, 1
     341: goto          293
     344: aload         16
     346: astore        4
     348: aload         5
     350: aload         4
     352: checkcast     #170                // class "[Ljava/lang/Object;"
     355: invokestatic  #176                // Method kotlin/collections/ArraysKt.last:([Ljava/lang/Object;)Ljava/lang/Object;
     358: invokeinterface #180,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     363: pop
     364: iinc          12, 1
     367: goto          143
     370: nop
     371: nop
     372: goto          77
     375: nop
     376: aload         5
     378: areturn

  private final Pos nextTailPos(Pos, Pos);
    Code:
       0: aload_1
       1: invokevirtual #156                // Method Pos.getX:()I
       4: aload_2
       5: invokevirtual #156                // Method Pos.getX:()I
       8: isub
       9: istore_3
      10: aload_1
      11: invokevirtual #159                // Method Pos.getY:()I
      14: aload_2
      15: invokevirtual #159                // Method Pos.getY:()I
      18: isub
      19: istore        4
      21: iload_3
      22: invokestatic  #205                // Method java/lang/Math.abs:(I)I
      25: iconst_1
      26: if_icmpgt     38
      29: iload         4
      31: invokestatic  #205                // Method java/lang/Math.abs:(I)I
      34: iconst_1
      35: if_icmple     85
      38: aload_2
      39: invokevirtual #208                // Method Pos.component1:()I
      42: istore        5
      44: aload_2
      45: invokevirtual #211                // Method Pos.component2:()I
      48: istore        6
      50: iload         5
      52: iload_3
      53: i2d
      54: invokestatic  #215                // Method java/lang/Math.signum:(D)D
      57: d2i
      58: iadd
      59: istore        5
      61: iload         6
      63: iload         4
      65: i2d
      66: invokestatic  #215                // Method java/lang/Math.signum:(D)D
      69: d2i
      70: iadd
      71: istore        6
      73: new           #104                // class Pos
      76: dup
      77: iload         5
      79: iload         6
      81: invokespecial #107                // Method Pos."<init>":(II)V
      84: areturn
      85: aload_2
      86: areturn

  private static final Move readInput$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #222                // String it
       3: invokestatic  #228                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #230                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #232                // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #234                // String
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #240                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_1
      30: aload_1
      31: iconst_0
      32: invokeinterface #244,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: checkcast     #232                // class java/lang/String
      40: astore_3
      41: aload_3
      42: invokevirtual #247                // Method java/lang/String.hashCode:()I
      45: lookupswitch  { // 4
                    68: 100
                    76: 125
                    82: 88
                    85: 112
               default: 162
          }
      88: aload_3
      89: ldc           #249                // String R
      91: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      94: ifne          156
      97: goto          162
     100: aload_3
     101: ldc           #254                // String D
     103: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     106: ifne          144
     109: goto          162
     112: aload_3
     113: ldc_w         #256                // String U
     116: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     119: ifne          138
     122: goto          162
     125: aload_3
     126: ldc_w         #258                // String L
     129: invokevirtual #252                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     132: ifne          150
     135: goto          162
     138: getstatic     #262                // Field Direction.Up:LDirection;
     141: goto          199
     144: getstatic     #265                // Field Direction.Down:LDirection;
     147: goto          199
     150: getstatic     #268                // Field Direction.Left:LDirection;
     153: goto          199
     156: getstatic     #271                // Field Direction.Right:LDirection;
     159: goto          199
     162: new           #273                // class java/lang/Error
     165: dup
     166: new           #17                 // class java/lang/StringBuilder
     169: dup
     170: invokespecial #18                 // Method java/lang/StringBuilder."<init>":()V
     173: ldc_w         #275                // String Unexpected direction
     176: invokevirtual #24                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     179: aload_1
     180: iconst_0
     181: invokeinterface #244,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #232                // class java/lang/String
     189: invokevirtual #24                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     192: invokevirtual #49                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     195: invokespecial #278                // Method java/lang/Error."<init>":(Ljava/lang/String;)V
     198: athrow
     199: astore_2
     200: aload_1
     201: iconst_1
     202: invokeinterface #244,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     207: checkcast     #232                // class java/lang/String
     210: bipush        10
     212: invokestatic  #283                // Method kotlin/text/CharsKt.checkRadix:(I)I
     215: invokestatic  #289                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     218: istore_3
     219: new           #130                // class Move
     222: dup
     223: aload_2
     224: iload_3
     225: invokespecial #292                // Method Move."<init>":(LDirection;I)V
     228: areturn

  static {};
    Code:
       0: new           #2                  // class Rope
       3: dup
       4: invokespecial #300                // Method "<init>":()V
       7: putstatic     #164                // Field INSTANCE:LRope;
      10: return
}

Compiled from "Rope.kt"
final class Rope$readInput$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function0<java.lang.String> {
  public static final Rope$readInput$1 INSTANCE;

  Rope$readInput$1();
    Code:
       0: aload_0
       1: iconst_0
       2: ldc           #11                 // class kotlin/io/ConsoleKt
       4: ldc           #13                 // String readLine
       6: ldc           #15                 // String readLine()Ljava/lang/String;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.String invoke();
    Code:
       0: invokestatic  #24                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: areturn

  public java.lang.Object invoke();
    Code:
       0: aload_0
       1: invokevirtual #27                 // Method invoke:()Ljava/lang/String;
       4: areturn

  static {};
    Code:
       0: new           #2                  // class Rope$readInput$1
       3: dup
       4: invokespecial #30                 // Method "<init>":()V
       7: putstatic     #33                 // Field INSTANCE:LRope$readInput$1;
      10: return
}

Compiled from "Rope.kt"
public final class Rope$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

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

Compiled from "Rope.kt"
public final class RopeKt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field Rope.INSTANCE:LRope;
       3: invokevirtual #15                 // Method Rope.solve:()V
       6: return

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


import kotlin.math.abs

fun main() = AocMap.solve()

private object AocMap {
    fun solve() {
        val (board, moves) = readInput()
        println("$moves")
//        board.print()
//        val pos = applyMoves(board, moves)
        println("Board size ${board.cells.size}x${board.cells.first().size}")
        println("Cube size ${board.cubeSize()}")
        // Hardcoded for input shape
        val cubeRegions = listOf(
            Pair(0, 1), Pair(0, 2),
            Pair(1, 1),
            Pair(2, 0), Pair(2, 1),
            Pair(3, 0)
        )
//        println("After moves: $pos ${getScore(pos)}")
    }

    private fun applyMoves(board: Board, moves: List<Move>): State {
        var state = board.findInitialState()
        println("Initial state: $state")
        for (move in moves) {
            state = board.applyMove(state, move)
            println("$move $state")
        }
        return state
    }

    private fun getScore(state: State): Int {
        return (state.y + 1) * 1000 + (state.x + 1) * 4 + when (state.facing) {
            Facing.Right -> 0
            Facing.Down -> 1
            Facing.Left -> 2
            Facing.Up -> 3
        }
    }

    fun readInput(): Pair<Board, List<Move>> {
        val rows = mutableListOf<List<Cell>>()
        var inMapSection = true
        var maxWidth = 0
        for (line in generateSequence(::readLine)) {
            if (inMapSection) {
                if (line == "") {
                    inMapSection = false
                    continue
                }
                val cells = line.toCharArray().map {
                    when (it) {
                        ' ' -> Cell.None
                        '.' -> Cell.Empty
                        '#' -> Cell.Wall
                        else -> throw Error("Unexpected char")
                    }
                }.toMutableList()
                maxWidth = maxOf(maxWidth, cells.size)
                if (cells.size < maxWidth) {
                    cells.addAll((1..maxWidth - cells.size).map { Cell.None })
                }
                rows.add(cells)
            } else {
                val moves = "(\\d+)(L|R|$)".toRegex().findAll(line).map { match ->
                    var rotateRight = 0
                    if (match.groupValues[2] == "L") {
                        rotateRight = -1
                    } else if (match.groupValues[2] == "R") {
                        rotateRight = 1
                    }
                    Move(match.groupValues[1].toInt(10), rotateRight)
                }.toList()
                return Pair(Board(rows), moves)
            }
        }

        val moves = listOf<Move>()
        return Pair(Board(rows), moves)
    }

    enum class Facing {
        Right,
        Down,
        Left,
        Up;

        fun rotate(rotateRight: Int): Facing {
            var i = this.ordinal + rotateRight
            if (i == -1) {
                i = Facing.values().size - 1
            } else if (i >= Facing.values().size) {
                i = 0
            }
            return Facing.values()[i]
        }
    }

    data class Move(val len: Int, val rotateRight: Int)

    data class Board(val cells: List<List<Cell>>) {
        fun cubeSize(): Int {
            return cells.first().count { it != Cell.None } / 2
        }

        fun findInitialState(): State {
            return State(cells.first().indexOfFirst { it == Cell.Empty }, 0, Facing.Right)
        }

        fun applyMove(state: State, move: Move): State {
            var x = state.x
            var y = state.y
            when (state.facing) {
                Facing.Right -> x = moveX(state, move.len)
                Facing.Down -> y = moveY(state, move.len)
                Facing.Left -> x = moveX(state, -move.len)
                Facing.Up -> y = moveY(state, -move.len)
            }
            val facing = state.facing.rotate(move.rotateRight)
            return State(x, y, facing)
        }

        private fun moveX(state: State, dx: Int): Int {
            val range = 1..abs(dx)
            val step = dx / abs(dx)
            var x = state.x
            for (i in range) {
                var nextX = x + step
                if (nextX == cells.first().size) {
                    nextX = 0
                } else if (nextX < 0) {
                    nextX = cells.first().size - 1
                }
                while (cells[state.y][nextX] == Cell.None) {
                    nextX += step
                    if (nextX == cells.first().size) {
                        nextX = 0
                    } else if (nextX < 0) {
                        nextX = cells.first().size - 1
                    }
                }
                if (cells[state.y][nextX] == Cell.Wall) {
                    return x
                } else {
                    x = nextX
                }
            }
            return x
        }

        private fun moveY(state: State, dy: Int): Int {
            val range = 1..abs(dy)
            val step = dy / abs(dy)
            var y = state.y
            for (i in range) {
                var next = y + step
                if (next == cells.size) {
                    next = 0
                } else if (next < 0) {
                    next = cells.size - 1
                }
                while (cells[next][state.x] == Cell.None) {
                    next += step
                    if (next == cells.size) {
                        next = 0
                    } else if (next < 0) {
                        next = cells.size - 1
                    }
                }
                if (cells[next][state.x] == Cell.Wall) {
                    return y
                } else {
                    y = next
                }
            }
            return y
        }

        fun print() {
            for (row in cells) {
                println(row.map {
                    when (it) {
                        Cell.None -> ' '
                        Cell.Empty -> '.'
                        Cell.Wall -> '#'
                    }
                }.joinToString(""))
            }
        }

    }

    enum class Cell {
        None,
        Empty,
        Wall
    }

    data class State(val x: Int, val y: Int, val facing: Facing)
}

Compiled from "Map.kt"
public final class MapKt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field AocMap.INSTANCE:LAocMap;
       3: invokevirtual #15                 // Method AocMap.solve:()V
       6: return

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


// Day4
fun main() {
    val sections = readInput()
    val fullyContained = sections.count { fullyContains(it.first, it.second) || fullyContains(it.second, it.first) }
    val overlapping = sections.count { overlaps(it.first, it.second) }
    println("# of fully contained ${fullyContained}")
    println("# of overlapping ${overlapping}")
}

private fun readInput(): Iterable<Section> {
    val result = mutableListOf<Section>()
    generateSequence(::readLine).forEach {
        val segments = it.split(',').map(::parsePair)
        result.add(Pair(segments[0], segments[1]))
    }
    return result
}

private typealias Segment = Pair<Int, Int>
private typealias Section = Pair<Segment, Segment>

private fun parsePair(string: String) : Pair<Int, Int> {
    val parts = string.split('-')
    return Pair(parts[0].toInt(10), parts[1].toInt(10))
}
private fun fullyContains(a: Segment, b: Segment) = a.first <= b.first && a.second >= b.second

private fun overlaps(a: Segment, b: Segment) = (a.first <= b.first && a.second >= b.first) || (a.first <= b.second && a.second >= b.first)

Compiled from "Cleanup.kt"
public final class CleanupKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readInput:()Ljava/lang/Iterable;
       3: astore_0
       4: aload_0
       5: astore_2
       6: iconst_0
       7: istore_3
       8: aload_2
       9: instanceof    #12                 // class java/util/Collection
      12: ifeq          31
      15: aload_2
      16: checkcast     #12                 // class java/util/Collection
      19: invokeinterface #16,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      24: ifeq          31
      27: iconst_0
      28: goto          139
      31: iconst_0
      32: istore        4
      34: aload_2
      35: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        5
      42: aload         5
      44: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          137
      52: aload         5
      54: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        6
      61: aload         6
      63: checkcast     #33                 // class kotlin/Pair
      66: astore        7
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      76: checkcast     #33                 // class kotlin/Pair
      79: aload         7
      81: invokevirtual #39                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      84: checkcast     #33                 // class kotlin/Pair
      87: invokestatic  #43                 // Method fullyContains:(Lkotlin/Pair;Lkotlin/Pair;)Z
      90: ifne          115
      93: aload         7
      95: invokevirtual #39                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      98: checkcast     #33                 // class kotlin/Pair
     101: aload         7
     103: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     106: checkcast     #33                 // class kotlin/Pair
     109: invokestatic  #43                 // Method fullyContains:(Lkotlin/Pair;Lkotlin/Pair;)Z
     112: ifeq          119
     115: iconst_1
     116: goto          120
     119: iconst_0
     120: ifeq          42
     123: iinc          4, 1
     126: iload         4
     128: ifge          42
     131: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     134: goto          42
     137: iload         4
     139: istore_1
     140: aload_0
     141: astore_3
     142: iconst_0
     143: istore        4
     145: aload_3
     146: instanceof    #12                 // class java/util/Collection
     149: ifeq          168
     152: aload_3
     153: checkcast     #12                 // class java/util/Collection
     156: invokeinterface #16,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     161: ifeq          168
     164: iconst_0
     165: goto          246
     168: iconst_0
     169: istore        5
     171: aload_3
     172: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     177: astore        6
     179: aload         6
     181: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     186: ifeq          244
     189: aload         6
     191: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     196: astore        7
     198: aload         7
     200: checkcast     #33                 // class kotlin/Pair
     203: astore        8
     205: iconst_0
     206: istore        9
     208: aload         8
     210: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     213: checkcast     #33                 // class kotlin/Pair
     216: aload         8
     218: invokevirtual #39                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     221: checkcast     #33                 // class kotlin/Pair
     224: invokestatic  #51                 // Method overlaps:(Lkotlin/Pair;Lkotlin/Pair;)Z
     227: ifeq          179
     230: iinc          5, 1
     233: iload         5
     235: ifge          179
     238: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     241: goto          179
     244: iload         5
     246: istore_2
     247: new           #53                 // class java/lang/StringBuilder
     250: dup
     251: invokespecial #56                 // Method java/lang/StringBuilder."<init>":()V
     254: ldc           #58                 // String # of fully contained
     256: invokevirtual #62                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     259: iload_1
     260: invokevirtual #65                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     263: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     266: getstatic     #75                 // Field java/lang/System.out:Ljava/io/PrintStream;
     269: swap
     270: invokevirtual #81                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     273: new           #53                 // class java/lang/StringBuilder
     276: dup
     277: invokespecial #56                 // Method java/lang/StringBuilder."<init>":()V
     280: ldc           #83                 // String # of overlapping
     282: invokevirtual #62                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     285: iload_2
     286: invokevirtual #65                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     289: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     292: getstatic     #75                 // Field java/lang/System.out:Ljava/io/PrintStream;
     295: swap
     296: invokevirtual #81                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     299: return

  private static final java.lang.Iterable<kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>> readInput();
    Code:
       0: new           #100                // class java/util/ArrayList
       3: dup
       4: invokespecial #101                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #103                // class java/util/List
      10: astore_0
      11: getstatic     #109                // Field CleanupKt$readInput$1.INSTANCE:LCleanupKt$readInput$1;
      14: checkcast     #111                // class kotlin/jvm/functions/Function0
      17: invokestatic  #117                // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
      20: astore_1
      21: iconst_0
      22: istore_2
      23: aload_1
      24: invokeinterface #120,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      29: astore_3
      30: aload_3
      31: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          219
      39: aload_3
      40: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      45: astore        4
      47: aload         4
      49: checkcast     #122                // class java/lang/String
      52: astore        5
      54: iconst_0
      55: istore        6
      57: aload         5
      59: checkcast     #124                // class java/lang/CharSequence
      62: iconst_1
      63: newarray       char
      65: astore        7
      67: aload         7
      69: iconst_0
      70: bipush        44
      72: castore
      73: aload         7
      75: iconst_0
      76: iconst_0
      77: bipush        6
      79: aconst_null
      80: invokestatic  #130                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
      83: checkcast     #18                 // class java/lang/Iterable
      86: astore        7
      88: iconst_0
      89: istore        8
      91: aload         7
      93: astore        9
      95: new           #100                // class java/util/ArrayList
      98: dup
      99: aload         7
     101: bipush        10
     103: invokestatic  #134                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     106: invokespecial #137                // Method java/util/ArrayList."<init>":(I)V
     109: checkcast     #12                 // class java/util/Collection
     112: astore        10
     114: iconst_0
     115: istore        11
     117: aload         9
     119: invokeinterface #22,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     124: astore        12
     126: aload         12
     128: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     133: ifeq          176
     136: aload         12
     138: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     143: astore        13
     145: aload         10
     147: aload         13
     149: checkcast     #122                // class java/lang/String
     152: astore        14
     154: astore        15
     156: iconst_0
     157: istore        16
     159: aload         14
     161: invokestatic  #141                // Method parsePair:(Ljava/lang/String;)Lkotlin/Pair;
     164: aload         15
     166: swap
     167: invokeinterface #145,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     172: pop
     173: goto          126
     176: aload         10
     178: checkcast     #103                // class java/util/List
     181: nop
     182: astore        17
     184: aload_0
     185: new           #33                 // class kotlin/Pair
     188: dup
     189: aload         17
     191: iconst_0
     192: invokeinterface #149,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     197: aload         17
     199: iconst_1
     200: invokeinterface #149,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     205: invokespecial #152                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     208: invokeinterface #153,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     213: pop
     214: nop
     215: nop
     216: goto          30
     219: nop
     220: aload_0
     221: checkcast     #18                 // class java/lang/Iterable
     224: areturn

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> parsePair(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #124                // class java/lang/CharSequence
       4: iconst_1
       5: newarray       char
       7: astore_2
       8: aload_2
       9: iconst_0
      10: bipush        45
      12: castore
      13: aload_2
      14: iconst_0
      15: iconst_0
      16: bipush        6
      18: aconst_null
      19: invokestatic  #130                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
      22: astore_1
      23: new           #33                 // class kotlin/Pair
      26: dup
      27: aload_1
      28: iconst_0
      29: invokeinterface #149,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      34: checkcast     #122                // class java/lang/String
      37: bipush        10
      39: invokestatic  #177                // Method kotlin/text/CharsKt.checkRadix:(I)I
      42: invokestatic  #183                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      45: invokestatic  #187                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      48: aload_1
      49: iconst_1
      50: invokeinterface #149,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      55: checkcast     #122                // class java/lang/String
      58: bipush        10
      60: invokestatic  #177                // Method kotlin/text/CharsKt.checkRadix:(I)I
      63: invokestatic  #183                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      66: invokestatic  #187                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      69: invokespecial #152                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      72: areturn

  private static final boolean fullyContains(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       4: checkcast     #192                // class java/lang/Number
       7: invokevirtual #196                // Method java/lang/Number.intValue:()I
      10: aload_1
      11: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      14: checkcast     #192                // class java/lang/Number
      17: invokevirtual #196                // Method java/lang/Number.intValue:()I
      20: if_icmpgt     50
      23: aload_0
      24: invokevirtual #39                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      27: checkcast     #192                // class java/lang/Number
      30: invokevirtual #196                // Method java/lang/Number.intValue:()I
      33: aload_1
      34: invokevirtual #39                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      37: checkcast     #192                // class java/lang/Number
      40: invokevirtual #196                // Method java/lang/Number.intValue:()I
      43: if_icmplt     50
      46: iconst_1
      47: goto          51
      50: iconst_0
      51: ireturn

  private static final boolean overlaps(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       4: checkcast     #192                // class java/lang/Number
       7: invokevirtual #196                // Method java/lang/Number.intValue:()I
      10: aload_1
      11: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      14: checkcast     #192                // class java/lang/Number
      17: invokevirtual #196                // Method java/lang/Number.intValue:()I
      20: if_icmpgt     46
      23: aload_0
      24: invokevirtual #39                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      27: checkcast     #192                // class java/lang/Number
      30: invokevirtual #196                // Method java/lang/Number.intValue:()I
      33: aload_1
      34: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      37: checkcast     #192                // class java/lang/Number
      40: invokevirtual #196                // Method java/lang/Number.intValue:()I
      43: if_icmpge     92
      46: aload_0
      47: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      50: checkcast     #192                // class java/lang/Number
      53: invokevirtual #196                // Method java/lang/Number.intValue:()I
      56: aload_1
      57: invokevirtual #39                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      60: checkcast     #192                // class java/lang/Number
      63: invokevirtual #196                // Method java/lang/Number.intValue:()I
      66: if_icmpgt     96
      69: aload_0
      70: invokevirtual #39                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      73: checkcast     #192                // class java/lang/Number
      76: invokevirtual #196                // Method java/lang/Number.intValue:()I
      79: aload_1
      80: invokevirtual #36                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      83: checkcast     #192                // class java/lang/Number
      86: invokevirtual #196                // Method java/lang/Number.intValue:()I
      89: if_icmplt     96
      92: iconst_1
      93: goto          97
      96: iconst_0
      97: ireturn

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

Compiled from "Cleanup.kt"
final class CleanupKt$readInput$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function0<java.lang.String> {
  public static final CleanupKt$readInput$1 INSTANCE;

  CleanupKt$readInput$1();
    Code:
       0: aload_0
       1: iconst_0
       2: ldc           #11                 // class kotlin/io/ConsoleKt
       4: ldc           #13                 // String readLine
       6: ldc           #15                 // String readLine()Ljava/lang/String;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.String invoke();
    Code:
       0: invokestatic  #24                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: areturn

  public java.lang.Object invoke();
    Code:
       0: aload_0
       1: invokevirtual #27                 // Method invoke:()Ljava/lang/String;
       4: areturn

  static {};
    Code:
       0: new           #2                  // class CleanupKt$readInput$1
       3: dup
       4: invokespecial #30                 // Method "<init>":()V
       7: putstatic     #33                 // Field INSTANCE:LCleanupKt$readInput$1;
      10: return
}


import java.io.*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.functions.*
import kotlin.jvm.internal.*
import kotlin.ranges.*
import kotlin.sequences.*
import kotlin.text.*

// Complete the journeyToMoon function below.
fun journeyToMoon(n: Int, pairs: Array<Array<Int>>): Long {
  val nodeEdges = kotlin.arrayOfNulls<MutableList<Int>>(n)
  for (pair in pairs) {
    val (a, b) = pair
    val aNodeEdges = nodeEdges[a] ?: mutableListOf<Int>()
    val bNodeEdges = nodeEdges[b] ?: mutableListOf<Int>()
    aNodeEdges.add(b)
    bNodeEdges.add(a)
    nodeEdges[a] = aNodeEdges
    nodeEdges[b] = bNodeEdges
  }

  val visitedNodes = BooleanArray(n)

  fun countNodes(node: Int): Int {
    if (visitedNodes[node]) {
      return 0
    }
    visitedNodes[node] = true
    var nodeCount = 1
    val nextNodes = nodeEdges[node]
    if (nextNodes == null) {
      return 1
    }
    for (nextNode in nextNodes) {
      nodeCount += countNodes(nextNode)
    }
    return nodeCount
  }

  val countries = mutableListOf<Int>()
  var countryWithSingleNodeCount = 0
  for (node in 0 until n) {
    val nodeCount = countNodes(node)
    if (nodeCount == 0) {
      continue
    }

    if (nodeCount == 1) {
      countryWithSingleNodeCount++
    } else {
      countries.add(nodeCount)
    }
  }

  var totalCount = 0L
  for (i in 0 until countries.size) {
    for (j in i + 1 until countries.size) {
      totalCount += countries[i].toLong() * countries[j].toLong()
    }
  }

  // pair single node with multiple nodes
  for (countryCount in countries) {
    totalCount += countryCount * countryWithSingleNodeCount.toLong()
  }

  // pair single node with single node
  totalCount += (countryWithSingleNodeCount) * (countryWithSingleNodeCount.toLong() - 1) / 2

  return totalCount
}

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

  val np = scan.nextLine().split(" ")

  val n = np[0].trim().toInt()

  val p = np[1].trim().toInt()

  val astronaut = Array<Array<Int>>(p, { Array<Int>(2, { 0 }) })

  for (i in 0 until p) {
    astronaut[i] = scan.nextLine().split(" ").map { it.trim().toInt() }.toTypedArray()
  }

  val result = journeyToMoon(n, astronaut)

  println(result)
}

Compiled from "Solution.kt"
public final class SolutionKt {
  public static final long journeyToMoon(int, java.lang.Integer[][]);
    Code:
       0: aload_1
       1: ldc           #9                  // String pairs
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_0
       7: anewarray     #17                 // class java/util/List
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_1
      14: checkcast     #19                 // class "[Ljava/lang/Object;"
      17: arraylength
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     141
      26: aload_1
      27: iload_3
      28: aaload
      29: astore        5
      31: aload         5
      33: iconst_0
      34: aaload
      35: checkcast     #21                 // class java/lang/Number
      38: invokevirtual #25                 // Method java/lang/Number.intValue:()I
      41: istore        6
      43: aload         5
      45: iconst_1
      46: aaload
      47: checkcast     #21                 // class java/lang/Number
      50: invokevirtual #25                 // Method java/lang/Number.intValue:()I
      53: istore        7
      55: aload_2
      56: iload         6
      58: aaload
      59: dup
      60: ifnonnull     74
      63: pop
      64: new           #27                 // class java/util/ArrayList
      67: dup
      68: invokespecial #31                 // Method java/util/ArrayList."<init>":()V
      71: checkcast     #17                 // class java/util/List
      74: astore        8
      76: aload_2
      77: iload         7
      79: aaload
      80: dup
      81: ifnonnull     95
      84: pop
      85: new           #27                 // class java/util/ArrayList
      88: dup
      89: invokespecial #31                 // Method java/util/ArrayList."<init>":()V
      92: checkcast     #17                 // class java/util/List
      95: astore        9
      97: aload         8
      99: iload         7
     101: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: invokeinterface #41,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     109: pop
     110: aload         9
     112: iload         6
     114: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: invokeinterface #41,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     122: pop
     123: aload_2
     124: iload         6
     126: aload         8
     128: aastore
     129: aload_2
     130: iload         7
     132: aload         9
     134: aastore
     135: iinc          3, 1
     138: goto          20
     141: iload_0
     142: newarray       boolean
     144: astore_3
     145: new           #27                 // class java/util/ArrayList
     148: dup
     149: invokespecial #31                 // Method java/util/ArrayList."<init>":()V
     152: checkcast     #17                 // class java/util/List
     155: astore        4
     157: iconst_0
     158: istore        5
     160: iconst_0
     161: istore        6
     163: iload         6
     165: iload_0
     166: if_icmpge     220
     169: aload_3
     170: aload_2
     171: iload         6
     173: invokestatic  #45                 // Method journeyToMoon$countNodes:([Z[Ljava/util/List;I)I
     176: istore        7
     178: iload         7
     180: ifne          186
     183: goto          214
     186: iload         7
     188: iconst_1
     189: if_icmpne     201
     192: iload         5
     194: iinc          5, 1
     197: pop
     198: goto          214
     201: aload         4
     203: iload         7
     205: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     208: invokeinterface #41,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     213: pop
     214: iinc          6, 1
     217: goto          163
     220: lconst_0
     221: lstore        6
     223: iconst_0
     224: istore        8
     226: aload         4
     228: invokeinterface #48,  1           // InterfaceMethod java/util/List.size:()I
     233: istore        9
     235: iload         8
     237: iload         9
     239: if_icmpge     314
     242: iload         8
     244: iconst_1
     245: iadd
     246: istore        10
     248: aload         4
     250: invokeinterface #48,  1           // InterfaceMethod java/util/List.size:()I
     255: istore        11
     257: iload         10
     259: iload         11
     261: if_icmpge     308
     264: lload         6
     266: aload         4
     268: iload         8
     270: invokeinterface #52,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     275: checkcast     #21                 // class java/lang/Number
     278: invokevirtual #25                 // Method java/lang/Number.intValue:()I
     281: i2l
     282: aload         4
     284: iload         10
     286: invokeinterface #52,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     291: checkcast     #21                 // class java/lang/Number
     294: invokevirtual #25                 // Method java/lang/Number.intValue:()I
     297: i2l
     298: lmul
     299: ladd
     300: lstore        6
     302: iinc          10, 1
     305: goto          257
     308: iinc          8, 1
     311: goto          235
     314: aload         4
     316: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     321: astore        8
     323: aload         8
     325: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     330: ifeq          363
     333: aload         8
     335: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     340: checkcast     #21                 // class java/lang/Number
     343: invokevirtual #25                 // Method java/lang/Number.intValue:()I
     346: istore        9
     348: lload         6
     350: iload         9
     352: i2l
     353: iload         5
     355: i2l
     356: lmul
     357: ladd
     358: lstore        6
     360: goto          323
     363: lload         6
     365: iload         5
     367: i2l
     368: iload         5
     370: i2l
     371: lconst_1
     372: lsub
     373: lmul
     374: iconst_2
     375: i2l
     376: ldiv
     377: ladd
     378: lstore        6
     380: lload         6
     382: lreturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #97                 // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #99                 // class java/util/Scanner
       9: dup
      10: getstatic     #105                // Field java/lang/System.in:Ljava/io/InputStream;
      13: invokespecial #108                // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      16: astore_1
      17: aload_1
      18: invokevirtual #112                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      21: dup
      22: ldc           #114                // String nextLine(...)
      24: invokestatic  #117                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      27: checkcast     #119                // class java/lang/CharSequence
      30: iconst_1
      31: anewarray     #121                // class java/lang/String
      34: astore_3
      35: aload_3
      36: iconst_0
      37: ldc           #123                // String
      39: aastore
      40: aload_3
      41: iconst_0
      42: iconst_0
      43: bipush        6
      45: aconst_null
      46: invokestatic  #129                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      49: astore_2
      50: nop
      51: aload_2
      52: iconst_0
      53: invokeinterface #52,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      58: checkcast     #121                // class java/lang/String
      61: checkcast     #119                // class java/lang/CharSequence
      64: invokestatic  #133                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      67: invokevirtual #136                // Method java/lang/Object.toString:()Ljava/lang/String;
      70: invokestatic  #140                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      73: istore_3
      74: nop
      75: aload_2
      76: iconst_1
      77: invokeinterface #52,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      82: checkcast     #121                // class java/lang/String
      85: checkcast     #119                // class java/lang/CharSequence
      88: invokestatic  #133                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      91: invokevirtual #136                // Method java/lang/Object.toString:()Ljava/lang/String;
      94: invokestatic  #140                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      97: istore        4
      99: iconst_0
     100: istore        6
     102: iload         4
     104: anewarray     #92                 // class "[Ljava/lang/Integer;"
     107: astore        7
     109: iload         6
     111: iload         4
     113: if_icmpge     175
     116: iload         6
     118: istore        8
     120: aload         7
     122: iload         8
     124: iconst_0
     125: istore        9
     127: iconst_2
     128: anewarray     #33                 // class java/lang/Integer
     131: astore        10
     133: istore        17
     135: astore        16
     137: iload         9
     139: iconst_2
     140: if_icmpge     162
     143: iload         9
     145: istore        11
     147: aload         10
     149: iload         11
     151: iconst_0
     152: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     155: aastore
     156: iinc          9, 1
     159: goto          137
     162: aload         16
     164: iload         17
     166: aload         10
     168: aastore
     169: iinc          6, 1
     172: goto          109
     175: aload         7
     177: astore        5
     179: iconst_0
     180: istore        6
     182: iload         6
     184: iload         4
     186: if_icmpge     384
     189: aload         5
     191: iload         6
     193: aload_1
     194: invokevirtual #112                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
     197: dup
     198: ldc           #114                // String nextLine(...)
     200: invokestatic  #117                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     203: checkcast     #119                // class java/lang/CharSequence
     206: iconst_1
     207: anewarray     #121                // class java/lang/String
     210: astore        7
     212: aload         7
     214: iconst_0
     215: ldc           #123                // String
     217: aastore
     218: aload         7
     220: iconst_0
     221: iconst_0
     222: bipush        6
     224: aconst_null
     225: invokestatic  #129                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     228: checkcast     #142                // class java/lang/Iterable
     231: astore        7
     233: istore        17
     235: astore        16
     237: iconst_0
     238: istore        8
     240: aload         7
     242: astore        9
     244: new           #27                 // class java/util/ArrayList
     247: dup
     248: aload         7
     250: bipush        10
     252: invokestatic  #148                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     255: invokespecial #151                // Method java/util/ArrayList."<init>":(I)V
     258: checkcast     #153                // class java/util/Collection
     261: astore        10
     263: iconst_0
     264: istore        11
     266: aload         9
     268: invokeinterface #154,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     273: astore        12
     275: aload         12
     277: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     282: ifeq          339
     285: aload         12
     287: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     292: astore        13
     294: aload         10
     296: aload         13
     298: checkcast     #121                // class java/lang/String
     301: astore        14
     303: astore        18
     305: iconst_0
     306: istore        15
     308: nop
     309: aload         14
     311: checkcast     #119                // class java/lang/CharSequence
     314: invokestatic  #133                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     317: invokevirtual #136                // Method java/lang/Object.toString:()Ljava/lang/String;
     320: invokestatic  #140                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     323: nop
     324: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     327: aload         18
     329: swap
     330: invokeinterface #155,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     335: pop
     336: goto          275
     339: aload         10
     341: checkcast     #17                 // class java/util/List
     344: nop
     345: astore        18
     347: aload         16
     349: iload         17
     351: aload         18
     353: checkcast     #153                // class java/util/Collection
     356: astore        7
     358: nop
     359: iconst_0
     360: istore        8
     362: aload         7
     364: astore        9
     366: aload         9
     368: iconst_0
     369: anewarray     #33                 // class java/lang/Integer
     372: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     377: aastore
     378: iinc          6, 1
     381: goto          182
     384: iload_3
     385: aload         5
     387: invokestatic  #161                // Method journeyToMoon:(I[[Ljava/lang/Integer;)J
     390: lstore        6
     392: getstatic     #165                // Field java/lang/System.out:Ljava/io/PrintStream;
     395: lload         6
     397: invokevirtual #171                // Method java/io/PrintStream.println:(J)V
     400: return

  private static final int journeyToMoon$countNodes(boolean[], java.util.List<java.lang.Integer>[], int);
    Code:
       0: aload_0
       1: iload_2
       2: baload
       3: ifeq          8
       6: iconst_0
       7: ireturn
       8: aload_0
       9: iload_2
      10: iconst_1
      11: bastore
      12: iconst_1
      13: istore_3
      14: aload_1
      15: iload_2
      16: aaload
      17: astore        4
      19: aload         4
      21: ifnonnull     26
      24: iconst_1
      25: ireturn
      26: aload         4
      28: invokeinterface #56,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      33: astore        5
      35: aload         5
      37: invokeinterface #62,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          73
      45: aload         5
      47: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: checkcast     #21                 // class java/lang/Number
      55: invokevirtual #25                 // Method java/lang/Number.intValue:()I
      58: istore        6
      60: iload_3
      61: aload_0
      62: aload_1
      63: iload         6
      65: invokestatic  #45                 // Method journeyToMoon$countNodes:([Z[Ljava/util/List;I)I
      68: iadd
      69: istore_3
      70: goto          35
      73: iload_3
      74: ireturn
}


import java.io.File
import java.math.BigInteger
import java.util.stream.Stream

/**
 * Problem

A sequence is an ordered collection of objects (usually numbers), which are allowed to repeat. Sequences can be finite or infinite. Two examples are the finite sequence (π,−2–√,0,π)(π,−2,0,π) and the infinite sequence of odd numbers (1,3,5,7,9,…)(1,3,5,7,9,…). We use the notation anan to represent the nn-th term of a sequence.

A recurrence relation is a way of defining the terms of a sequence with respect to the values of previous terms. In the case of Fibonacci's rabbits from the introduction, any given month will contain the rabbits that were alive the previous month, plus any new offspring. A key observation is that the number of offspring in any month is equal to the number of rabbits that were alive two months prior. As a result, if FnFn represents the number of rabbit pairs alive after the nn-th month, then we obtain the Fibonacci sequence having terms FnFn that are defined by the recurrence relation Fn=Fn−1+Fn−2Fn=Fn−1+Fn−2 (with F1=F2=1F1=F2=1 to initiate the sequence). Although the sequence bears Fibonacci's name, it was known to Indian mathematicians over two millennia ago.

When finding the nn-th term of a sequence defined by a recurrence relation, we can simply use the recurrence relation to generate terms for progressively larger values of nn. This problem introduces us to the computational technique of dynamic programming, which successively builds up solutions by using the answers to smaller cases.

Given: Positive integers n≤40n≤40 and k≤5k≤5.

Return: The total number of rabbit pairs that will be present after nn months, if we begin with 1 pair and in each generation, every pair of reproduction-age rabbits produces a litter of kk rabbit pairs (instead of only 1 pair).
 */
fun main(args: Array<String>) {
  val fib = File("rosalind_fib.txt").readLines()[0];
  val list = fib.split(" ")
  val n = list[0].toLong()
  val k = BigInteger(list[1])
  Stream.iterate(Pair(BigInteger.ONE, BigInteger.ZERO), { pair -> Pair(pair.second * k, pair.first + pair.second) })
      .skip(n - 1L)
      .findFirst()
      .ifPresent{pair -> println(pair.first + pair.second)}
}

Compiled from "P4FIB.kt"
public final class P4FIBKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class java/io/File
       9: dup
      10: ldc           #19                 // String rosalind_fib.txt
      12: invokespecial #23                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      15: aconst_null
      16: iconst_1
      17: aconst_null
      18: invokestatic  #29                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      21: iconst_0
      22: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      27: checkcast     #37                 // class java/lang/String
      30: astore_1
      31: aload_1
      32: checkcast     #39                 // class java/lang/CharSequence
      35: iconst_1
      36: anewarray     #37                 // class java/lang/String
      39: astore_3
      40: aload_3
      41: iconst_0
      42: ldc           #41                 // String
      44: aastore
      45: aload_3
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #47                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      54: astore_2
      55: aload_2
      56: iconst_0
      57: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      62: checkcast     #37                 // class java/lang/String
      65: invokestatic  #53                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      68: lstore_3
      69: new           #55                 // class java/math/BigInteger
      72: dup
      73: aload_2
      74: iconst_1
      75: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      80: checkcast     #37                 // class java/lang/String
      83: invokespecial #56                 // Method java/math/BigInteger."<init>":(Ljava/lang/String;)V
      86: astore        5
      88: new           #58                 // class kotlin/Pair
      91: dup
      92: getstatic     #62                 // Field java/math/BigInteger.ONE:Ljava/math/BigInteger;
      95: getstatic     #65                 // Field java/math/BigInteger.ZERO:Ljava/math/BigInteger;
      98: invokespecial #68                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     101: aload         5
     103: invokedynamic #88,  0             // InvokeDynamic #0:apply:(Ljava/math/BigInteger;)Ljava/util/function/UnaryOperator;
     108: invokestatic  #94                 // InterfaceMethod java/util/stream/Stream.iterate:(Ljava/lang/Object;Ljava/util/function/UnaryOperator;)Ljava/util/stream/Stream;
     111: lload_3
     112: lconst_1
     113: lsub
     114: invokeinterface #98,  3           // InterfaceMethod java/util/stream/Stream.skip:(J)Ljava/util/stream/Stream;
     119: invokeinterface #102,  1          // InterfaceMethod java/util/stream/Stream.findFirst:()Ljava/util/Optional;
     124: invokedynamic #112,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
     129: invokedynamic #123,  0            // InvokeDynamic #2:accept:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/Consumer;
     134: invokevirtual #129                // Method java/util/Optional.ifPresent:(Ljava/util/function/Consumer;)V
     137: return

  private static final kotlin.Pair main$lambda$0(java.math.BigInteger, kotlin.Pair);
    Code:
       0: new           #58                 // class kotlin/Pair
       3: dup
       4: aload_1
       5: invokevirtual #141                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
       8: dup
       9: ldc           #143                // String <get-second>(...)
      11: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      14: checkcast     #55                 // class java/math/BigInteger
      17: aload_0
      18: invokevirtual #150                // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      21: dup
      22: ldc           #152                // String multiply(...)
      24: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      27: aload_1
      28: invokevirtual #155                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      31: dup
      32: ldc           #157                // String <get-first>(...)
      34: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      37: checkcast     #55                 // class java/math/BigInteger
      40: astore_2
      41: aload_1
      42: invokevirtual #141                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      45: dup
      46: ldc           #143                // String <get-second>(...)
      48: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      51: checkcast     #55                 // class java/math/BigInteger
      54: aload_2
      55: swap
      56: invokevirtual #160                // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      59: dup
      60: ldc           #162                // String add(...)
      62: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      65: invokespecial #68                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      68: areturn

  private static final kotlin.Unit main$lambda$1(kotlin.Pair);
    Code:
       0: aload_0
       1: ldc           #166                // String pair
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #155                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      10: dup
      11: ldc           #157                // String <get-first>(...)
      13: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      16: checkcast     #55                 // class java/math/BigInteger
      19: astore_1
      20: aload_0
      21: invokevirtual #141                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      24: dup
      25: ldc           #143                // String <get-second>(...)
      27: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      30: checkcast     #55                 // class java/math/BigInteger
      33: aload_1
      34: swap
      35: invokevirtual #160                // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      38: dup
      39: ldc           #162                // String add(...)
      41: invokestatic  #146                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      44: astore_1
      45: getstatic     #172                // Field java/lang/System.out:Ljava/io/PrintStream;
      48: aload_1
      49: invokevirtual #177                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      52: getstatic     #183                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      55: areturn

  private static final void main$lambda$2(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #187,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: pop
       8: return
}


class TwoStringMasks {
    private val IMPOSSIBLE: String = "impossible"

    private fun String.trim(b: Int): String {
        var i = b
        while (this[i] != '*')
            ++i
        return removeRange(i, i + 1)
    }

    private fun String.combine(b1: Int, e1: Int, other: String, b2: Int, e2: Int): String {
        val nb2 = b2 + 1
        var tb1 = b1
        var l1 = e1 - tb1
        val l2 = e2 - nb2 + 1
        if (l1 > l2) {
            tb1 += l1 - l2
            l1 = l2
        }
        while (tb1 < e1 && subSequence(tb1, tb1 + l1) != other.subSequence(nb2, nb2 + l1)) {
            ++tb1
            --l1
        }
        val sb = StringBuilder(tb1 + other.length - b2)
        sb.append(this, 0, tb1)
        sb.append(other, nb2, other.length)
        return sb.toString()
    }

    fun shortestCommon(s1: String, s2: String): String {
        var b1 = 0
        var b2 = 0
        var c1 = s1[b1]
        var c2 = s2[b2]
        while (c1 != '*' && c2 != '*') {
            if (c1 != c2)
                return IMPOSSIBLE
            c1 = s1[++b1]
            c2 = s2[++b2]
        }

        var e1 = s1.length - 1
        var e2 = s2.length - 1
        c1 = s1[e1]
        c2 = s2[e2]
        while (c1 != '*' && c2 != '*') {
            if (c1 != c2)
                return IMPOSSIBLE
            c1 = s1[--e1]
            c2 = s2[--e2]
        }

        return when {
            b1 == e1 -> s2.trim(b2)
            b2 == e2 -> s1.trim(b1)
            s1[e1] == '*' -> s1.combine(b1, e1, s2, b2, e2)
            else -> s2.combine(b2, e2, s1, b1, e1)
        }
    }
}

Compiled from "TwoStringMasks.kt"
public final class TwoStringMasks {
  private final java.lang.String IMPOSSIBLE;

  public TwoStringMasks();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: ldc           #10                 // String impossible
       7: putfield      #14                 // Field IMPOSSIBLE:Ljava/lang/String;
      10: return

  private final java.lang.String trim(java.lang.String, int);
    Code:
       0: iload_2
       1: istore_3
       2: aload_1
       3: iload_3
       4: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
       7: bipush        42
       9: if_icmpeq     18
      12: iinc          3, 1
      15: goto          2
      18: aload_1
      19: astore        4
      21: iload_3
      22: iconst_1
      23: iadd
      24: istore        5
      26: aload         4
      28: checkcast     #26                 // class java/lang/CharSequence
      31: iload_3
      32: iload         5
      34: invokestatic  #32                 // Method kotlin/text/StringsKt.removeRange:(Ljava/lang/CharSequence;II)Ljava/lang/CharSequence;
      37: invokevirtual #36                 // Method java/lang/Object.toString:()Ljava/lang/String;
      40: areturn

  private final java.lang.String combine(java.lang.String, int, int, java.lang.String, int, int);
    Code:
       0: iload         5
       2: iconst_1
       3: iadd
       4: istore        7
       6: iload_2
       7: istore        8
       9: iload_3
      10: iload         8
      12: isub
      13: istore        9
      15: iload         6
      17: iload         7
      19: isub
      20: iconst_1
      21: iadd
      22: istore        10
      24: iload         9
      26: iload         10
      28: if_icmple     45
      31: iload         8
      33: iload         9
      35: iload         10
      37: isub
      38: iadd
      39: istore        8
      41: iload         10
      43: istore        9
      45: iload         8
      47: iload_3
      48: if_icmpge     89
      51: aload_1
      52: iload         8
      54: iload         8
      56: iload         9
      58: iadd
      59: invokevirtual #46                 // Method java/lang/String.subSequence:(II)Ljava/lang/CharSequence;
      62: aload         4
      64: iload         7
      66: iload         7
      68: iload         9
      70: iadd
      71: invokevirtual #46                 // Method java/lang/String.subSequence:(II)Ljava/lang/CharSequence;
      74: invokestatic  #52                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      77: ifne          89
      80: iinc          8, 1
      83: iinc          9, -1
      86: goto          45
      89: new           #54                 // class java/lang/StringBuilder
      92: dup
      93: iload         8
      95: aload         4
      97: invokevirtual #58                 // Method java/lang/String.length:()I
     100: iadd
     101: iload         5
     103: isub
     104: invokespecial #61                 // Method java/lang/StringBuilder."<init>":(I)V
     107: astore        11
     109: aload         11
     111: aload_1
     112: checkcast     #26                 // class java/lang/CharSequence
     115: iconst_0
     116: iload         8
     118: invokevirtual #65                 // Method java/lang/StringBuilder.append:(Ljava/lang/CharSequence;II)Ljava/lang/StringBuilder;
     121: pop
     122: aload         11
     124: aload         4
     126: checkcast     #26                 // class java/lang/CharSequence
     129: iload         7
     131: aload         4
     133: invokevirtual #58                 // Method java/lang/String.length:()I
     136: invokevirtual #65                 // Method java/lang/StringBuilder.append:(Ljava/lang/CharSequence;II)Ljava/lang/StringBuilder;
     139: pop
     140: aload         11
     142: invokevirtual #66                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     145: dup
     146: ldc           #68                 // String toString(...)
     148: invokestatic  #72                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     151: areturn

  public final java.lang.String shortestCommon(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #89                 // String s1
       3: invokestatic  #92                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #94                 // String s2
       9: invokestatic  #92                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_3
      14: iconst_0
      15: istore        4
      17: aload_1
      18: iload_3
      19: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
      22: istore        5
      24: aload_2
      25: iload         4
      27: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
      30: istore        6
      32: iload         5
      34: bipush        42
      36: if_icmpeq     82
      39: iload         6
      41: bipush        42
      43: if_icmpeq     82
      46: iload         5
      48: iload         6
      50: if_icmpeq     58
      53: aload_0
      54: getfield      #14                 // Field IMPOSSIBLE:Ljava/lang/String;
      57: areturn
      58: aload_1
      59: iinc          3, 1
      62: iload_3
      63: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
      66: istore        5
      68: aload_2
      69: iinc          4, 1
      72: iload         4
      74: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
      77: istore        6
      79: goto          32
      82: aload_1
      83: invokevirtual #58                 // Method java/lang/String.length:()I
      86: iconst_1
      87: isub
      88: istore        7
      90: aload_2
      91: invokevirtual #58                 // Method java/lang/String.length:()I
      94: iconst_1
      95: isub
      96: istore        8
      98: aload_1
      99: iload         7
     101: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
     104: istore        5
     106: aload_2
     107: iload         8
     109: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
     112: istore        6
     114: iload         5
     116: bipush        42
     118: if_icmpeq     165
     121: iload         6
     123: bipush        42
     125: if_icmpeq     165
     128: iload         5
     130: iload         6
     132: if_icmpeq     140
     135: aload_0
     136: getfield      #14                 // Field IMPOSSIBLE:Ljava/lang/String;
     139: areturn
     140: aload_1
     141: iinc          7, -1
     144: iload         7
     146: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
     149: istore        5
     151: aload_2
     152: iinc          8, -1
     155: iload         8
     157: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
     160: istore        6
     162: goto          114
     165: nop
     166: iload_3
     167: iload         7
     169: if_icmpne     182
     172: aload_0
     173: aload_2
     174: iload         4
     176: invokespecial #96                 // Method trim:(Ljava/lang/String;I)Ljava/lang/String;
     179: goto          238
     182: iload         4
     184: iload         8
     186: if_icmpne     198
     189: aload_0
     190: aload_1
     191: iload_3
     192: invokespecial #96                 // Method trim:(Ljava/lang/String;I)Ljava/lang/String;
     195: goto          238
     198: aload_1
     199: iload         7
     201: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
     204: bipush        42
     206: if_icmpne     225
     209: aload_0
     210: aload_1
     211: iload_3
     212: iload         7
     214: aload_2
     215: iload         4
     217: iload         8
     219: invokespecial #98                 // Method combine:(Ljava/lang/String;IILjava/lang/String;II)Ljava/lang/String;
     222: goto          238
     225: aload_0
     226: aload_2
     227: iload         4
     229: iload         8
     231: aload_1
     232: iload_3
     233: iload         7
     235: invokespecial #98                 // Method combine:(Ljava/lang/String;IILjava/lang/String;II)Ljava/lang/String;
     238: areturn
}