package day09

import java.io.File
import kotlin.math.absoluteValue
import kotlin.math.sign

fun main() {
    val data = parse("src/main/kotlin/day09/Day09.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 09 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

@Suppress("SameParameterValue")
private fun parse(path: String): List<Pair<String, Int>> =
    File(path).readLines()
        .map { it.split(" ") }
        .map { (move, step) -> move to step.toInt() }

private data class Knot(
    var x: Int,
    var y: Int,
)

private fun MutableList<Knot>.move(direction: String) {
    when (direction) {
        "U" -> this[0].y += 1
        "D" -> this[0].y -= 1
        "R" -> this[0].x += 1
        "L" -> this[0].x -= 1
    }

    for ((head, tail) in this.zipWithNext()) {
        val dx = head.x - tail.x
        val dy = head.y - tail.y

        if (dx.absoluteValue < 2 && dy.absoluteValue < 2) {
            return
        }

        tail.x += dx.sign
        tail.y += dy.sign
    }
}

private fun solve(data: List<Pair<String, Int>>, count: Int): Int {
    val rope = generateSequence { Knot(0, 0) }
        .take(count)
        .toMutableList()

    val visited = mutableSetOf(Knot(0, 0))
    for ((direction, steps) in data) {
        repeat(steps) {
            rope.move(direction)
            visited += rope.last().copy()
        }
    }

    return visited.size
}

private fun part1(data: List<Pair<String, Int>>): Int =
    solve(data, count = 2)

private fun part2(data: List<Pair<String, Int>>): Int =
    solve(data, count = 10)

Compiled from "Day09.kt"
public final class day09.Day09Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day09/Day09.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method part1:(Ljava/util/List;)I
      10: istore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Ljava/util/List;)I
      15: istore_2
      16: ldc           #21                 // String 🎄 Day 09 🎄
      18: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      31: ldc           #37                 // String [Part 1]
      33: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: new           #39                 // class java/lang/StringBuilder
      43: dup
      44: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #44                 // String Answer:
      49: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: iload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      56: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      72: ldc           #57                 // String [Part 2]
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: new           #39                 // class java/lang/StringBuilder
      84: dup
      85: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      88: ldc           #44                 // String Answer:
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: iload_2
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      97: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: swap
     104: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     107: return

  private static final java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>> parse(java.lang.String);
    Code:
       0: new           #65                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #68                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #74                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #76                 // class java/lang/Iterable
      17: astore_1
      18: nop
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #78                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #87                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #89                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          124
      62: aload         6
      64: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #105                // class java/lang/String
      78: astore        8
      80: astore        12
      82: iconst_0
      83: istore        9
      85: aload         8
      87: checkcast     #107                // class java/lang/CharSequence
      90: iconst_1
      91: anewarray     #105                // class java/lang/String
      94: astore        10
      96: aload         10
      98: iconst_0
      99: ldc           #109                // String
     101: aastore
     102: aload         10
     104: iconst_0
     105: iconst_0
     106: bipush        6
     108: aconst_null
     109: invokestatic  #115                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     112: aload         12
     114: swap
     115: invokeinterface #119,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     120: pop
     121: goto          52
     124: aload         4
     126: checkcast     #121                // class java/util/List
     129: nop
     130: checkcast     #76                 // class java/lang/Iterable
     133: astore_1
     134: nop
     135: iconst_0
     136: istore_2
     137: aload_1
     138: astore_3
     139: new           #78                 // class java/util/ArrayList
     142: dup
     143: aload_1
     144: bipush        10
     146: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     149: invokespecial #87                 // Method java/util/ArrayList."<init>":(I)V
     152: checkcast     #89                 // class java/util/Collection
     155: astore        4
     157: iconst_0
     158: istore        5
     160: aload_3
     161: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     166: astore        6
     168: aload         6
     170: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     175: ifeq          252
     178: aload         6
     180: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     185: astore        7
     187: aload         4
     189: aload         7
     191: checkcast     #121                // class java/util/List
     194: astore        8
     196: astore        12
     198: iconst_0
     199: istore        9
     201: aload         8
     203: iconst_0
     204: invokeinterface #125,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     209: checkcast     #105                // class java/lang/String
     212: astore        10
     214: aload         8
     216: iconst_1
     217: invokeinterface #125,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     222: checkcast     #105                // class java/lang/String
     225: astore        11
     227: aload         10
     229: aload         11
     231: invokestatic  #131                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     234: invokestatic  #135                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     237: invokestatic  #141                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     240: aload         12
     242: swap
     243: invokeinterface #119,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     248: pop
     249: goto          168
     252: aload         4
     254: checkcast     #121                // class java/util/List
     257: nop
     258: areturn

  private static final void move(java.util.List<day09.Knot>, java.lang.String);
    Code:
       0: aload_1
       1: astore_2
       2: aload_2
       3: invokevirtual #163                // Method java/lang/String.hashCode:()I
       6: lookupswitch  { // 4
                    68: 60
                    76: 84
                    82: 48
                    85: 72
               default: 189
          }
      48: aload_2
      49: ldc           #165                // String R
      51: invokevirtual #168                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      54: ifne          144
      57: goto          189
      60: aload_2
      61: ldc           #170                // String D
      63: invokevirtual #168                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      66: ifne          120
      69: goto          189
      72: aload_2
      73: ldc           #172                // String U
      75: invokevirtual #168                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      78: ifne          96
      81: goto          189
      84: aload_2
      85: ldc           #174                // String L
      87: invokevirtual #168                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      90: ifne          168
      93: goto          189
      96: aload_0
      97: iconst_0
      98: invokeinterface #125,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     103: checkcast     #176                // class day09/Knot
     106: astore_3
     107: aload_3
     108: aload_3
     109: invokevirtual #179                // Method day09/Knot.getY:()I
     112: iconst_1
     113: iadd
     114: invokevirtual #182                // Method day09/Knot.setY:(I)V
     117: goto          189
     120: aload_0
     121: iconst_0
     122: invokeinterface #125,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     127: checkcast     #176                // class day09/Knot
     130: astore_3
     131: aload_3
     132: aload_3
     133: invokevirtual #179                // Method day09/Knot.getY:()I
     136: iconst_1
     137: isub
     138: invokevirtual #182                // Method day09/Knot.setY:(I)V
     141: goto          189
     144: aload_0
     145: iconst_0
     146: invokeinterface #125,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     151: checkcast     #176                // class day09/Knot
     154: astore_3
     155: aload_3
     156: aload_3
     157: invokevirtual #185                // Method day09/Knot.getX:()I
     160: iconst_1
     161: iadd
     162: invokevirtual #188                // Method day09/Knot.setX:(I)V
     165: goto          189
     168: aload_0
     169: iconst_0
     170: invokeinterface #125,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     175: checkcast     #176                // class day09/Knot
     178: astore_3
     179: aload_3
     180: aload_3
     181: invokevirtual #185                // Method day09/Knot.getX:()I
     184: iconst_1
     185: isub
     186: invokevirtual #188                // Method day09/Knot.setX:(I)V
     189: aload_0
     190: checkcast     #76                 // class java/lang/Iterable
     193: invokestatic  #192                // Method kotlin/collections/CollectionsKt.zipWithNext:(Ljava/lang/Iterable;)Ljava/util/List;
     196: invokeinterface #193,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     201: astore_2
     202: aload_2
     203: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     208: ifeq          319
     211: aload_2
     212: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     217: checkcast     #195                // class kotlin/Pair
     220: astore_3
     221: aload_3
     222: invokevirtual #198                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     225: checkcast     #176                // class day09/Knot
     228: astore        4
     230: aload_3
     231: invokevirtual #201                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     234: checkcast     #176                // class day09/Knot
     237: astore        5
     239: aload         4
     241: invokevirtual #185                // Method day09/Knot.getX:()I
     244: aload         5
     246: invokevirtual #185                // Method day09/Knot.getX:()I
     249: isub
     250: istore        6
     252: aload         4
     254: invokevirtual #179                // Method day09/Knot.getY:()I
     257: aload         5
     259: invokevirtual #179                // Method day09/Knot.getY:()I
     262: isub
     263: istore        7
     265: iload         6
     267: invokestatic  #207                // Method java/lang/Math.abs:(I)I
     270: iconst_2
     271: if_icmpge     284
     274: iload         7
     276: invokestatic  #207                // Method java/lang/Math.abs:(I)I
     279: iconst_2
     280: if_icmpge     284
     283: return
     284: aload         5
     286: aload         5
     288: invokevirtual #185                // Method day09/Knot.getX:()I
     291: iload         6
     293: invokestatic  #212                // Method kotlin/math/MathKt.getSign:(I)I
     296: iadd
     297: invokevirtual #188                // Method day09/Knot.setX:(I)V
     300: aload         5
     302: aload         5
     304: invokevirtual #179                // Method day09/Knot.getY:()I
     307: iload         7
     309: invokestatic  #212                // Method kotlin/math/MathKt.getSign:(I)I
     312: iadd
     313: invokevirtual #182                // Method day09/Knot.setY:(I)V
     316: goto          202
     319: return

  private static final int solve(java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>>, int);
    Code:
       0: invokedynamic #240,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function0;
       5: invokestatic  #246                // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
       8: iload_1
       9: invokestatic  #250                // Method kotlin/sequences/SequencesKt.take:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
      12: invokestatic  #254                // Method kotlin/sequences/SequencesKt.toMutableList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      15: astore_2
      16: iconst_1
      17: anewarray     #176                // class day09/Knot
      20: astore        4
      22: aload         4
      24: iconst_0
      25: new           #176                // class day09/Knot
      28: dup
      29: iconst_0
      30: iconst_0
      31: invokespecial #257                // Method day09/Knot."<init>":(II)V
      34: aastore
      35: aload         4
      37: invokestatic  #263                // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      40: astore_3
      41: aload_0
      42: invokeinterface #193,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      47: astore        4
      49: aload         4
      51: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      56: ifeq          148
      59: aload         4
      61: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      66: checkcast     #195                // class kotlin/Pair
      69: astore        5
      71: aload         5
      73: invokevirtual #198                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      76: checkcast     #105                // class java/lang/String
      79: astore        6
      81: aload         5
      83: invokevirtual #201                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      86: checkcast     #265                // class java/lang/Number
      89: invokevirtual #268                // Method java/lang/Number.intValue:()I
      92: istore        7
      94: iconst_0
      95: istore        8
      97: iload         8
      99: iload         7
     101: if_icmpge     49
     104: iload         8
     106: istore        9
     108: iconst_0
     109: istore        10
     111: aload_2
     112: aload         6
     114: invokestatic  #270                // Method move:(Ljava/util/List;Ljava/lang/String;)V
     117: aload_3
     118: checkcast     #89                 // class java/util/Collection
     121: aload_2
     122: invokestatic  #274                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     125: checkcast     #176                // class day09/Knot
     128: iconst_0
     129: iconst_0
     130: iconst_3
     131: aconst_null
     132: invokestatic  #278                // Method day09/Knot.copy$default:(Lday09/Knot;IIILjava/lang/Object;)Lday09/Knot;
     135: invokeinterface #119,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     140: pop
     141: nop
     142: iinc          8, 1
     145: goto          97
     148: aload_3
     149: invokeinterface #283,  1          // InterfaceMethod java/util/Set.size:()I
     154: ireturn

  private static final int part1(java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>>);
    Code:
       0: aload_0
       1: iconst_2
       2: invokestatic  #292                // Method solve:(Ljava/util/List;I)I
       5: ireturn

  private static final int part2(java.util.List<kotlin.Pair<java.lang.String, java.lang.Integer>>);
    Code:
       0: aload_0
       1: bipush        10
       3: invokestatic  #292                // Method solve:(Ljava/util/List;I)I
       6: ireturn

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

  private static final day09.Knot solve$lambda$2();
    Code:
       0: new           #176                // class day09/Knot
       3: dup
       4: iconst_0
       5: iconst_0
       6: invokespecial #257                // Method day09/Knot."<init>":(II)V
       9: areturn
}


package day08

import java.io.File

fun main() {
    val data = parse("src/main/kotlin/day08/Day08.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 08 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

@Suppress("SameParameterValue")
private fun parse(path: String): List<List<Int>> =
    File(path).useLines { lines ->
        lines.map { it.map(Char::digitToInt) }.toList()
    }

private fun part1(data: List<List<Int>>): Int {
    var counter = 0
    for (y in data.indices) {
        for (x in data[0].indices) {
            val current = data[y][x]
            if ((x - 1 downTo 0).all { i -> data[y][i] < current }) {
                counter += 1
                continue
            }
            if ((x + 1..data[0].lastIndex).all { i -> data[y][i] < current }) {
                counter += 1
                continue
            }
            if ((y - 1 downTo 0).all { i -> data[i][x] < current }) {
                counter += 1
                continue
            }
            if ((y + 1..data.lastIndex).all { i -> data[i][x] < current }) {
                counter += 1
                continue
            }
        }
    }

    return counter
}

private fun part2(data: List<List<Int>>): Int {
    val scores = mutableListOf<Int>()
    for (y in data.indices) {
        for (x in data[0].indices) {
            val current = data[y][x]

            val distances = Array(4) { 0 }
            for (i in (x - 1) downTo 0) {
                distances[0] += 1
                if (data[y][i] >= current) {
                    break
                }
            }
            for (i in (x + 1)..data[0].lastIndex) {
                distances[1] += 1
                if (data[y][i] >= current) {
                    break
                }
            }
            for (i in (y - 1) downTo 0) {
                distances[2] += 1
                if (data[i][x] >= current) {
                    break
                }
            }
            for (i in (y + 1)..data.lastIndex) {
                distances[3] += 1
                if (data[i][x] >= current) {
                    break
                }
            }

            scores.add(distances.reduce(Int::times))
        }
    }

    return scores.max()
}

Compiled from "Day08.kt"
public final class day08.Day08Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day08/Day08.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method part1:(Ljava/util/List;)I
      10: istore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Ljava/util/List;)I
      15: istore_2
      16: ldc           #21                 // String 🎄 Day 08 🎄
      18: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      31: ldc           #37                 // String [Part 1]
      33: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: new           #39                 // class java/lang/StringBuilder
      43: dup
      44: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #44                 // String Answer:
      49: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: iload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      56: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      72: ldc           #57                 // String [Part 2]
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: new           #39                 // class java/lang/StringBuilder
      84: dup
      85: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      88: ldc           #44                 // String Answer:
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: iload_2
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      97: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: swap
     104: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     107: return

  private static final java.util.List<java.util.List<java.lang.Integer>> parse(java.lang.String);
    Code:
       0: new           #67                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #70                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: astore_1
       9: getstatic     #76                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      12: astore_2
      13: iconst_0
      14: istore_3
      15: aload_1
      16: astore        4
      18: sipush        8192
      21: istore        5
      23: aload         4
      25: astore        6
      27: new           #78                 // class java/io/InputStreamReader
      30: dup
      31: new           #80                 // class java/io/FileInputStream
      34: dup
      35: aload         6
      37: invokespecial #83                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      40: checkcast     #85                 // class java/io/InputStream
      43: aload_2
      44: invokespecial #88                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      47: checkcast     #90                 // class java/io/Reader
      50: astore        6
      52: aload         6
      54: instanceof    #92                 // class java/io/BufferedReader
      57: ifeq          68
      60: aload         6
      62: checkcast     #92                 // class java/io/BufferedReader
      65: goto          79
      68: new           #92                 // class java/io/BufferedReader
      71: dup
      72: aload         6
      74: iload         5
      76: invokespecial #95                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      79: checkcast     #97                 // class java/io/Closeable
      82: astore        4
      84: aconst_null
      85: astore        5
      87: nop
      88: aload         4
      90: checkcast     #92                 // class java/io/BufferedReader
      93: astore        6
      95: iconst_0
      96: istore        7
      98: aload         6
     100: invokestatic  #103                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     103: astore        8
     105: iconst_0
     106: istore        9
     108: aload         8
     110: invokedynamic #121,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     115: invokestatic  #127                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     118: invokestatic  #131                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     121: astore        6
     123: aload         4
     125: aload         5
     127: invokestatic  #137                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     130: aload         6
     132: goto          156
     135: astore        7
     137: aload         7
     139: astore        5
     141: aload         7
     143: athrow
     144: astore        7
     146: aload         4
     148: aload         5
     150: invokestatic  #137                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     153: aload         7
     155: athrow
     156: nop
     157: areturn
    Exception table:
       from    to  target type
          87   123   135   Class java/lang/Throwable
          87   123   144   any
         135   144   144   any
         144   146   144   any

  private static final int part1(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: aload_0
       5: checkcast     #160                // class java/util/Collection
       8: invokeinterface #164,  1          // InterfaceMethod java/util/Collection.size:()I
      13: istore_3
      14: iload_2
      15: iload_3
      16: if_icmpge     612
      19: iconst_0
      20: istore        4
      22: aload_0
      23: iconst_0
      24: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      29: checkcast     #160                // class java/util/Collection
      32: invokeinterface #164,  1          // InterfaceMethod java/util/Collection.size:()I
      37: istore        5
      39: iload         4
      41: iload         5
      43: if_icmpge     606
      46: aload_0
      47: iload_2
      48: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      53: checkcast     #155                // class java/util/List
      56: iload         4
      58: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      63: checkcast     #170                // class java/lang/Number
      66: invokevirtual #173                // Method java/lang/Number.intValue:()I
      69: istore        6
      71: iload         4
      73: iconst_1
      74: isub
      75: iconst_0
      76: invokestatic  #179                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      79: checkcast     #181                // class java/lang/Iterable
      82: astore        7
      84: iconst_0
      85: istore        8
      87: aload         7
      89: instanceof    #160                // class java/util/Collection
      92: ifeq          112
      95: aload         7
      97: checkcast     #160                // class java/util/Collection
     100: invokeinterface #185,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     105: ifeq          112
     108: iconst_1
     109: goto          189
     112: aload         7
     114: invokeinterface #189,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     119: astore        9
     121: aload         9
     123: invokeinterface #194,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     128: ifeq          188
     131: aload         9
     133: checkcast     #196                // class kotlin/collections/IntIterator
     136: invokevirtual #199                // Method kotlin/collections/IntIterator.nextInt:()I
     139: istore        10
     141: iload         10
     143: istore        11
     145: iconst_0
     146: istore        12
     148: aload_0
     149: iload_2
     150: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     155: checkcast     #155                // class java/util/List
     158: iload         11
     160: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     165: checkcast     #170                // class java/lang/Number
     168: invokevirtual #173                // Method java/lang/Number.intValue:()I
     171: iload         6
     173: if_icmpge     180
     176: iconst_1
     177: goto          181
     180: iconst_0
     181: ifne          121
     184: iconst_0
     185: goto          189
     188: iconst_1
     189: ifeq          198
     192: iinc          1, 1
     195: goto          600
     198: new           #201                // class kotlin/ranges/IntRange
     201: dup
     202: iload         4
     204: iconst_1
     205: iadd
     206: aload_0
     207: iconst_0
     208: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     213: checkcast     #155                // class java/util/List
     216: invokestatic  #206                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     219: invokespecial #209                // Method kotlin/ranges/IntRange."<init>":(II)V
     222: checkcast     #181                // class java/lang/Iterable
     225: astore        7
     227: iconst_0
     228: istore        8
     230: aload         7
     232: instanceof    #160                // class java/util/Collection
     235: ifeq          255
     238: aload         7
     240: checkcast     #160                // class java/util/Collection
     243: invokeinterface #185,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     248: ifeq          255
     251: iconst_1
     252: goto          332
     255: aload         7
     257: invokeinterface #189,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     262: astore        9
     264: aload         9
     266: invokeinterface #194,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     271: ifeq          331
     274: aload         9
     276: checkcast     #196                // class kotlin/collections/IntIterator
     279: invokevirtual #199                // Method kotlin/collections/IntIterator.nextInt:()I
     282: istore        10
     284: iload         10
     286: istore        11
     288: iconst_0
     289: istore        12
     291: aload_0
     292: iload_2
     293: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     298: checkcast     #155                // class java/util/List
     301: iload         11
     303: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     308: checkcast     #170                // class java/lang/Number
     311: invokevirtual #173                // Method java/lang/Number.intValue:()I
     314: iload         6
     316: if_icmpge     323
     319: iconst_1
     320: goto          324
     323: iconst_0
     324: ifne          264
     327: iconst_0
     328: goto          332
     331: iconst_1
     332: ifeq          341
     335: iinc          1, 1
     338: goto          600
     341: iload_2
     342: iconst_1
     343: isub
     344: iconst_0
     345: invokestatic  #179                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
     348: checkcast     #181                // class java/lang/Iterable
     351: astore        7
     353: iconst_0
     354: istore        8
     356: aload         7
     358: instanceof    #160                // class java/util/Collection
     361: ifeq          381
     364: aload         7
     366: checkcast     #160                // class java/util/Collection
     369: invokeinterface #185,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     374: ifeq          381
     377: iconst_1
     378: goto          459
     381: aload         7
     383: invokeinterface #189,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     388: astore        9
     390: aload         9
     392: invokeinterface #194,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     397: ifeq          458
     400: aload         9
     402: checkcast     #196                // class kotlin/collections/IntIterator
     405: invokevirtual #199                // Method kotlin/collections/IntIterator.nextInt:()I
     408: istore        10
     410: iload         10
     412: istore        11
     414: iconst_0
     415: istore        12
     417: aload_0
     418: iload         11
     420: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     425: checkcast     #155                // class java/util/List
     428: iload         4
     430: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     435: checkcast     #170                // class java/lang/Number
     438: invokevirtual #173                // Method java/lang/Number.intValue:()I
     441: iload         6
     443: if_icmpge     450
     446: iconst_1
     447: goto          451
     450: iconst_0
     451: ifne          390
     454: iconst_0
     455: goto          459
     458: iconst_1
     459: ifeq          468
     462: iinc          1, 1
     465: goto          600
     468: new           #201                // class kotlin/ranges/IntRange
     471: dup
     472: iload_2
     473: iconst_1
     474: iadd
     475: aload_0
     476: invokestatic  #206                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     479: invokespecial #209                // Method kotlin/ranges/IntRange."<init>":(II)V
     482: checkcast     #181                // class java/lang/Iterable
     485: astore        7
     487: iconst_0
     488: istore        8
     490: aload         7
     492: instanceof    #160                // class java/util/Collection
     495: ifeq          515
     498: aload         7
     500: checkcast     #160                // class java/util/Collection
     503: invokeinterface #185,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     508: ifeq          515
     511: iconst_1
     512: goto          593
     515: aload         7
     517: invokeinterface #189,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     522: astore        9
     524: aload         9
     526: invokeinterface #194,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     531: ifeq          592
     534: aload         9
     536: checkcast     #196                // class kotlin/collections/IntIterator
     539: invokevirtual #199                // Method kotlin/collections/IntIterator.nextInt:()I
     542: istore        10
     544: iload         10
     546: istore        11
     548: iconst_0
     549: istore        12
     551: aload_0
     552: iload         11
     554: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     559: checkcast     #155                // class java/util/List
     562: iload         4
     564: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     569: checkcast     #170                // class java/lang/Number
     572: invokevirtual #173                // Method java/lang/Number.intValue:()I
     575: iload         6
     577: if_icmpge     584
     580: iconst_1
     581: goto          585
     584: iconst_0
     585: ifne          524
     588: iconst_0
     589: goto          593
     592: iconst_1
     593: ifeq          600
     596: iinc          1, 1
     599: nop
     600: iinc          4, 1
     603: goto          39
     606: iinc          2, 1
     609: goto          14
     612: iload_1
     613: ireturn

  private static final int part2(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: new           #224                // class java/util/ArrayList
       3: dup
       4: invokespecial #225                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #155                // class java/util/List
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_0
      14: checkcast     #160                // class java/util/Collection
      17: invokeinterface #164,  1          // InterfaceMethod java/util/Collection.size:()I
      22: istore_3
      23: iload_2
      24: iload_3
      25: if_icmpge     544
      28: iconst_0
      29: istore        4
      31: aload_0
      32: iconst_0
      33: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      38: checkcast     #160                // class java/util/Collection
      41: invokeinterface #164,  1          // InterfaceMethod java/util/Collection.size:()I
      46: istore        5
      48: iload         4
      50: iload         5
      52: if_icmpge     538
      55: aload_0
      56: iload_2
      57: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      62: checkcast     #155                // class java/util/List
      65: iload         4
      67: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      72: checkcast     #170                // class java/lang/Number
      75: invokevirtual #173                // Method java/lang/Number.intValue:()I
      78: istore        6
      80: iconst_0
      81: istore        8
      83: iconst_4
      84: anewarray     #227                // class java/lang/Integer
      87: astore        9
      89: iload         8
      91: iconst_4
      92: if_icmpge     114
      95: iload         8
      97: istore        10
      99: aload         9
     101: iload         10
     103: iconst_0
     104: invokestatic  #231                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     107: aastore
     108: iinc          8, 1
     111: goto          89
     114: aload         9
     116: astore        7
     118: iload         4
     120: iconst_1
     121: isub
     122: istore        8
     124: iconst_m1
     125: iload         8
     127: if_icmpge     183
     130: aload         7
     132: iconst_0
     133: aload         7
     135: iconst_0
     136: aaload
     137: invokevirtual #232                // Method java/lang/Integer.intValue:()I
     140: iconst_1
     141: iadd
     142: invokestatic  #231                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     145: aastore
     146: aload_0
     147: iload_2
     148: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     153: checkcast     #155                // class java/util/List
     156: iload         8
     158: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     163: checkcast     #170                // class java/lang/Number
     166: invokevirtual #173                // Method java/lang/Number.intValue:()I
     169: iload         6
     171: if_icmplt     177
     174: goto          183
     177: iinc          8, -1
     180: goto          124
     183: iload         4
     185: iconst_1
     186: iadd
     187: istore        8
     189: aload_0
     190: iconst_0
     191: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     196: checkcast     #155                // class java/util/List
     199: invokestatic  #206                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     202: istore        9
     204: iload         8
     206: iload         9
     208: if_icmpgt     271
     211: aload         7
     213: iconst_1
     214: aload         7
     216: iconst_1
     217: aaload
     218: invokevirtual #232                // Method java/lang/Integer.intValue:()I
     221: iconst_1
     222: iadd
     223: invokestatic  #231                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     226: aastore
     227: aload_0
     228: iload_2
     229: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     234: checkcast     #155                // class java/util/List
     237: iload         8
     239: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     244: checkcast     #170                // class java/lang/Number
     247: invokevirtual #173                // Method java/lang/Number.intValue:()I
     250: iload         6
     252: if_icmplt     258
     255: goto          271
     258: iload         8
     260: iload         9
     262: if_icmpeq     271
     265: iinc          8, 1
     268: goto          211
     271: iload_2
     272: iconst_1
     273: isub
     274: istore        8
     276: iconst_m1
     277: iload         8
     279: if_icmpge     336
     282: aload         7
     284: iconst_2
     285: aload         7
     287: iconst_2
     288: aaload
     289: invokevirtual #232                // Method java/lang/Integer.intValue:()I
     292: iconst_1
     293: iadd
     294: invokestatic  #231                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     297: aastore
     298: aload_0
     299: iload         8
     301: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     306: checkcast     #155                // class java/util/List
     309: iload         4
     311: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     316: checkcast     #170                // class java/lang/Number
     319: invokevirtual #173                // Method java/lang/Number.intValue:()I
     322: iload         6
     324: if_icmplt     330
     327: goto          336
     330: iinc          8, -1
     333: goto          276
     336: iload_2
     337: iconst_1
     338: iadd
     339: istore        8
     341: aload_0
     342: invokestatic  #206                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     345: istore        9
     347: iload         8
     349: iload         9
     351: if_icmpgt     415
     354: aload         7
     356: iconst_3
     357: aload         7
     359: iconst_3
     360: aaload
     361: invokevirtual #232                // Method java/lang/Integer.intValue:()I
     364: iconst_1
     365: iadd
     366: invokestatic  #231                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     369: aastore
     370: aload_0
     371: iload         8
     373: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     378: checkcast     #155                // class java/util/List
     381: iload         4
     383: invokeinterface #168,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     388: checkcast     #170                // class java/lang/Number
     391: invokevirtual #173                // Method java/lang/Number.intValue:()I
     394: iload         6
     396: if_icmplt     402
     399: goto          415
     402: iload         8
     404: iload         9
     406: if_icmpeq     415
     409: iinc          8, 1
     412: goto          354
     415: aload_1
     416: aload         7
     418: astore        8
     420: astore        16
     422: iconst_0
     423: istore        9
     425: aload         8
     427: arraylength
     428: ifne          435
     431: iconst_1
     432: goto          436
     435: iconst_0
     436: ifeq          449
     439: new           #234                // class java/lang/UnsupportedOperationException
     442: dup
     443: ldc           #236                // String Empty array can\'t be reduced.
     445: invokespecial #237                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     448: athrow
     449: aload         8
     451: iconst_0
     452: aaload
     453: astore        10
     455: iconst_1
     456: istore        11
     458: aload         8
     460: invokestatic  #242                // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     463: istore        12
     465: iload         11
     467: iload         12
     469: if_icmpgt     521
     472: aload         10
     474: aload         8
     476: iload         11
     478: aaload
     479: checkcast     #170                // class java/lang/Number
     482: invokevirtual #173                // Method java/lang/Number.intValue:()I
     485: istore        13
     487: checkcast     #170                // class java/lang/Number
     490: invokevirtual #173                // Method java/lang/Number.intValue:()I
     493: istore        14
     495: iconst_0
     496: istore        15
     498: iload         14
     500: iload         13
     502: imul
     503: invokestatic  #231                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     506: astore        10
     508: iload         11
     510: iload         12
     512: if_icmpeq     521
     515: iinc          11, 1
     518: goto          472
     521: aload         10
     523: aload         16
     525: swap
     526: invokeinterface #246,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     531: pop
     532: iinc          4, 1
     535: goto          48
     538: iinc          2, 1
     541: goto          23
     544: aload_1
     545: checkcast     #181                // class java/lang/Iterable
     548: invokestatic  #250                // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     551: checkcast     #170                // class java/lang/Number
     554: invokevirtual #173                // Method java/lang/Number.intValue:()I
     557: ireturn

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

  private static final java.util.List parse$lambda$1$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #270                // String it
       4: invokestatic  #276                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #278                // class java/lang/CharSequence
      11: astore_1
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #224                // class java/util/ArrayList
      19: dup
      20: aload_1
      21: invokeinterface #281,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      26: invokespecial #284                // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #160                // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: iconst_0
      38: istore        6
      40: iload         6
      42: aload_3
      43: invokeinterface #281,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      48: if_icmpge     95
      51: aload_3
      52: iload         6
      54: invokeinterface #288,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      59: istore        7
      61: aload         4
      63: iload         7
      65: istore        8
      67: astore        10
      69: iconst_0
      70: istore        9
      72: iload         8
      74: invokestatic  #294                // Method kotlin/text/CharsKt.digitToInt:(C)I
      77: invokestatic  #231                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         10
      82: swap
      83: invokeinterface #295,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: iinc          6, 1
      92: goto          40
      95: aload         4
      97: checkcast     #155                // class java/util/List
     100: nop
     101: areturn
}