package org.aoc2021

import java.nio.file.Files
import java.nio.file.Path

object Day9 {
    data class Point(val x: Int, val y: Int)

    private fun solvePart1(lines: List<String>): Int {
        val heights = lines.map { line ->
            line.map(Char::digitToInt)
        }
        val lowPoints = findLowPoints(heights)
        return lowPoints.sumOf { p ->
            1 + heights[p.x][p.y]
        }
    }

    private fun solvePart2(lines: List<String>): Int {
        val heights = lines.map { line ->
            line.map(Char::digitToInt)
        }
        val lowPoints = findLowPoints(heights)

        val basinMarkers = findBasins(heights, lowPoints)

        return basinMarkers.flatten()
            .filter { it != 0 }
            .groupBy { it }
            .map { (_, values) -> values.size }
            .sortedDescending()
            .take(3)
            .reduce { a, b -> a * b }
    }

    private fun findLowPoints(heights: List<List<Int>>): List<Point> {
        val lowPoints = mutableListOf<Point>()
        for (i in heights.indices) {
            for (j in heights[0].indices) {
                if (
                    (i == 0 || heights[i][j] < heights[i-1][j]) &&
                    (i == heights.size - 1 || heights[i][j] < heights[i+1][j]) &&
                    (j == 0 || heights[i][j] < heights[i][j-1]) &&
                    (j == heights[0].size - 1 || heights[i][j] < heights[i][j+1])
                ) {
                    lowPoints.add(Point(i, j))
                }
            }
        }
        return lowPoints.toList()
    }

    private fun findBasins(heights: List<List<Int>>, lowPoints: List<Point>): Array<Array<Int>> {
        val basinMarkers = Array(heights.size) { Array(heights[0].size) { 0 } }

        lowPoints.forEachIndexed { index, p ->
            val marker = index + 1
            fill(p, marker, heights, basinMarkers)
        }

        return basinMarkers
    }

    private fun fill(p: Point, marker: Int, heights: List<List<Int>>, basinMarkers: Array<Array<Int>>) {
        val (x, y) = p

        basinMarkers[x][y] = marker

        listOf(
            -1 to 0,
            1 to 0,
            0 to -1,
            0 to 1,
        ).forEach { (dx, dy) ->
            val i = x + dx
            val j = y + dy

            if (
                i >= 0 && i < heights.size &&
                j >= 0 && j < heights[0].size &&
                heights[i][j] != 9 && basinMarkers[i][j] == 0
            ) {
                fill(Point(i, j), marker, heights, basinMarkers)
            }
        }
    }

    @JvmStatic
    fun main(args: Array<String>) {
        val lines = Files.readAllLines(Path.of("input9.txt"), Charsets.UTF_8)
        val solution1 = solvePart1(lines)
        println(solution1)
        val solution2 = solvePart2(lines)
        println(solution2)
    }
}

Compiled from "Day9.kt"
public final class org.aoc2021.Day9$Point {
  private final int x;

  private final int y;

  public org.aoc2021.Day9$Point(int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field x:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field y:I
      14: return

  public final int getX();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: ireturn

  public final int getY();
    Code:
       0: aload_0
       1: getfield      #16                 // Field y:I
       4: ireturn

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: ireturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field y:I
       4: ireturn

  public final org.aoc2021.Day9$Point copy(int, int);
    Code:
       0: new           #2                  // class org/aoc2021/Day9$Point
       3: dup
       4: iload_1
       5: iload_2
       6: invokespecial #28                 // Method "<init>":(II)V
       9: areturn

  public static org.aoc2021.Day9$Point copy$default(org.aoc2021.Day9$Point, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #13                 // Field x:I
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #16                 // Field y:I
      21: istore_2
      22: aload_0
      23: iload_1
      24: iload_2
      25: invokevirtual #32                 // Method copy:(II)Lorg/aoc2021/Day9$Point;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #36                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #39                 // String Point(x=
       9: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field x:I
      16: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #48                 // String , y=
      21: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field y:I
      28: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #51                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #53                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: invokestatic  #59                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field y:I
      16: invokestatic  #59                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class org/aoc2021/Day9$Point
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class org/aoc2021/Day9$Point
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field x:I
      25: aload_2
      26: getfield      #13                 // Field x:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field y:I
      38: aload_2
      39: getfield      #16                 // Field y:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: iconst_1
      48: ireturn
}

Compiled from "Day9.kt"
public final class org.aoc2021.Day9 {
  public static final org.aoc2021.Day9 INSTANCE;

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

  private final int solvePart1(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #15                 // class java/lang/Iterable
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: astore        5
      11: new           #17                 // class java/util/ArrayList
      14: dup
      15: aload_3
      16: bipush        10
      18: invokestatic  #23                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #28                 // class java/util/Collection
      27: astore        6
      29: iconst_0
      30: istore        7
      32: aload         5
      34: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        8
      41: aload         8
      43: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          189
      51: aload         8
      53: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        9
      60: aload         6
      62: aload         9
      64: checkcast     #44                 // class java/lang/String
      67: astore        10
      69: astore        22
      71: iconst_0
      72: istore        11
      74: aload         10
      76: checkcast     #46                 // class java/lang/CharSequence
      79: astore        12
      81: iconst_0
      82: istore        13
      84: aload         12
      86: astore        14
      88: new           #17                 // class java/util/ArrayList
      91: dup
      92: aload         12
      94: invokeinterface #50,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      99: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
     102: checkcast     #28                 // class java/util/Collection
     105: astore        15
     107: iconst_0
     108: istore        16
     110: iconst_0
     111: istore        17
     113: iload         17
     115: aload         14
     117: invokeinterface #50,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     122: if_icmpge     170
     125: aload         14
     127: iload         17
     129: invokeinterface #54,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     134: istore        18
     136: aload         15
     138: iload         18
     140: istore        19
     142: astore        20
     144: iconst_0
     145: istore        21
     147: iload         19
     149: invokestatic  #60                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     152: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     155: aload         20
     157: swap
     158: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     163: pop
     164: iinc          17, 1
     167: goto          113
     170: aload         15
     172: checkcast     #72                 // class java/util/List
     175: nop
     176: nop
     177: aload         22
     179: swap
     180: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     185: pop
     186: goto          41
     189: aload         6
     191: checkcast     #72                 // class java/util/List
     194: nop
     195: astore_2
     196: aload_0
     197: aload_2
     198: invokespecial #76                 // Method findLowPoints:(Ljava/util/List;)Ljava/util/List;
     201: astore_3
     202: aload_3
     203: checkcast     #15                 // class java/lang/Iterable
     206: astore        4
     208: iconst_0
     209: istore        5
     211: aload         4
     213: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     218: astore        6
     220: aload         6
     222: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     227: ifeq          297
     230: aload         6
     232: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     237: astore        7
     239: iload         5
     241: aload         7
     243: checkcast     #78                 // class org/aoc2021/Day9$Point
     246: astore        8
     248: istore        22
     250: iconst_0
     251: istore        9
     253: iconst_1
     254: aload_2
     255: aload         8
     257: invokevirtual #81                 // Method org/aoc2021/Day9$Point.getX:()I
     260: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     265: checkcast     #72                 // class java/util/List
     268: aload         8
     270: invokevirtual #88                 // Method org/aoc2021/Day9$Point.getY:()I
     273: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     278: checkcast     #90                 // class java/lang/Number
     281: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     284: iadd
     285: istore        23
     287: iload         22
     289: iload         23
     291: iadd
     292: istore        5
     294: goto          220
     297: iload         5
     299: ireturn

  private final int solvePart2(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: checkcast     #15                 // class java/lang/Iterable
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: astore        5
      11: new           #17                 // class java/util/ArrayList
      14: dup
      15: aload_3
      16: bipush        10
      18: invokestatic  #23                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #28                 // class java/util/Collection
      27: astore        6
      29: iconst_0
      30: istore        7
      32: aload         5
      34: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        8
      41: aload         8
      43: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          189
      51: aload         8
      53: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        9
      60: aload         6
      62: aload         9
      64: checkcast     #44                 // class java/lang/String
      67: astore        10
      69: astore        22
      71: iconst_0
      72: istore        11
      74: aload         10
      76: checkcast     #46                 // class java/lang/CharSequence
      79: astore        12
      81: iconst_0
      82: istore        13
      84: aload         12
      86: astore        14
      88: new           #17                 // class java/util/ArrayList
      91: dup
      92: aload         12
      94: invokeinterface #50,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      99: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
     102: checkcast     #28                 // class java/util/Collection
     105: astore        15
     107: iconst_0
     108: istore        16
     110: iconst_0
     111: istore        17
     113: iload         17
     115: aload         14
     117: invokeinterface #50,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     122: if_icmpge     170
     125: aload         14
     127: iload         17
     129: invokeinterface #54,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     134: istore        18
     136: aload         15
     138: iload         18
     140: istore        19
     142: astore        20
     144: iconst_0
     145: istore        21
     147: iload         19
     149: invokestatic  #60                 // Method kotlin/text/CharsKt.digitToInt:(C)I
     152: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     155: aload         20
     157: swap
     158: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     163: pop
     164: iinc          17, 1
     167: goto          113
     170: aload         15
     172: checkcast     #72                 // class java/util/List
     175: nop
     176: nop
     177: aload         22
     179: swap
     180: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     185: pop
     186: goto          41
     189: aload         6
     191: checkcast     #72                 // class java/util/List
     194: nop
     195: astore_2
     196: aload_0
     197: aload_2
     198: invokespecial #76                 // Method findLowPoints:(Ljava/util/List;)Ljava/util/List;
     201: astore_3
     202: aload_0
     203: aload_2
     204: aload_3
     205: invokespecial #122                // Method findBasins:(Ljava/util/List;Ljava/util/List;)[[Ljava/lang/Integer;
     208: astore        4
     210: aload         4
     212: invokestatic  #128                // Method kotlin/collections/ArraysKt.flatten:([[Ljava/lang/Object;)Ljava/util/List;
     215: checkcast     #15                 // class java/lang/Iterable
     218: astore        5
     220: nop
     221: iconst_0
     222: istore        6
     224: aload         5
     226: astore        7
     228: new           #17                 // class java/util/ArrayList
     231: dup
     232: invokespecial #129                // Method java/util/ArrayList."<init>":()V
     235: checkcast     #28                 // class java/util/Collection
     238: astore        8
     240: iconst_0
     241: istore        9
     243: aload         7
     245: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     250: astore        10
     252: aload         10
     254: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     259: ifeq          310
     262: aload         10
     264: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     269: astore        11
     271: aload         11
     273: checkcast     #90                 // class java/lang/Number
     276: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     279: istore        12
     281: iconst_0
     282: istore        13
     284: iload         12
     286: ifeq          293
     289: iconst_1
     290: goto          294
     293: iconst_0
     294: ifeq          252
     297: aload         8
     299: aload         11
     301: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     306: pop
     307: goto          252
     310: aload         8
     312: checkcast     #72                 // class java/util/List
     315: nop
     316: checkcast     #15                 // class java/lang/Iterable
     319: astore        5
     321: nop
     322: iconst_0
     323: istore        6
     325: aload         5
     327: astore        7
     329: new           #131                // class java/util/LinkedHashMap
     332: dup
     333: invokespecial #132                // Method java/util/LinkedHashMap."<init>":()V
     336: checkcast     #134                // class java/util/Map
     339: astore        8
     341: iconst_0
     342: istore        9
     344: aload         7
     346: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     351: astore        10
     353: aload         10
     355: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     360: ifeq          468
     363: aload         10
     365: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     370: astore        11
     372: aload         11
     374: checkcast     #90                 // class java/lang/Number
     377: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     380: istore        12
     382: iconst_0
     383: istore        13
     385: iload         12
     387: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     390: astore        14
     392: aload         8
     394: astore        15
     396: iconst_0
     397: istore        16
     399: aload         15
     401: aload         14
     403: invokeinterface #137,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     408: astore        17
     410: aload         17
     412: ifnonnull     447
     415: iconst_0
     416: istore        18
     418: new           #17                 // class java/util/ArrayList
     421: dup
     422: invokespecial #129                // Method java/util/ArrayList."<init>":()V
     425: checkcast     #72                 // class java/util/List
     428: astore        18
     430: aload         15
     432: aload         14
     434: aload         18
     436: invokeinterface #141,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     441: pop
     442: aload         18
     444: goto          449
     447: aload         17
     449: nop
     450: checkcast     #72                 // class java/util/List
     453: astore        12
     455: aload         12
     457: aload         11
     459: invokeinterface #142,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     464: pop
     465: goto          353
     468: aload         8
     470: nop
     471: astore        5
     473: nop
     474: iconst_0
     475: istore        6
     477: aload         5
     479: astore        7
     481: new           #17                 // class java/util/ArrayList
     484: dup
     485: aload         5
     487: invokeinterface #145,  1          // InterfaceMethod java/util/Map.size:()I
     492: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
     495: checkcast     #28                 // class java/util/Collection
     498: astore        8
     500: iconst_0
     501: istore        9
     503: aload         7
     505: invokeinterface #149,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     510: invokeinterface #152,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     515: astore        10
     517: aload         10
     519: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     524: ifeq          584
     527: aload         10
     529: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     534: checkcast     #154                // class java/util/Map$Entry
     537: astore        11
     539: aload         8
     541: aload         11
     543: astore        12
     545: astore        22
     547: iconst_0
     548: istore        13
     550: aload         12
     552: invokeinterface #157,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     557: checkcast     #72                 // class java/util/List
     560: astore        14
     562: aload         14
     564: invokeinterface #158,  1          // InterfaceMethod java/util/List.size:()I
     569: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     572: aload         22
     574: swap
     575: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     580: pop
     581: goto          517
     584: aload         8
     586: checkcast     #72                 // class java/util/List
     589: nop
     590: checkcast     #15                 // class java/lang/Iterable
     593: invokestatic  #162                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     596: checkcast     #15                 // class java/lang/Iterable
     599: iconst_3
     600: invokestatic  #166                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     603: checkcast     #15                 // class java/lang/Iterable
     606: astore        5
     608: nop
     609: iconst_0
     610: istore        6
     612: aload         5
     614: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     619: astore        7
     621: aload         7
     623: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     628: ifne          641
     631: new           #168                // class java/lang/UnsupportedOperationException
     634: dup
     635: ldc           #170                // String Empty collection can\'t be reduced.
     637: invokespecial #173                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     640: athrow
     641: aload         7
     643: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     648: astore        8
     650: aload         7
     652: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     657: ifeq          701
     660: aload         8
     662: aload         7
     664: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     669: checkcast     #90                 // class java/lang/Number
     672: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     675: istore        9
     677: checkcast     #90                 // class java/lang/Number
     680: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     683: istore        10
     685: iconst_0
     686: istore        11
     688: iload         10
     690: iload         9
     692: imul
     693: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     696: astore        8
     698: goto          650
     701: aload         8
     703: checkcast     #90                 // class java/lang/Number
     706: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     709: ireturn

  private final java.util.List<org.aoc2021.Day9$Point> findLowPoints(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: new           #17                 // class java/util/ArrayList
       3: dup
       4: invokespecial #129                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #72                 // class java/util/List
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_1
      14: checkcast     #28                 // class java/util/Collection
      17: invokeinterface #211,  1          // InterfaceMethod java/util/Collection.size:()I
      22: istore        4
      24: iload_3
      25: iload         4
      27: if_icmpge     333
      30: iconst_0
      31: istore        5
      33: aload_1
      34: iconst_0
      35: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      40: checkcast     #28                 // class java/util/Collection
      43: invokeinterface #211,  1          // InterfaceMethod java/util/Collection.size:()I
      48: istore        6
      50: iload         5
      52: iload         6
      54: if_icmpge     327
      57: iload_3
      58: ifeq          112
      61: aload_1
      62: iload_3
      63: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #72                 // class java/util/List
      71: iload         5
      73: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      78: checkcast     #90                 // class java/lang/Number
      81: invokevirtual #93                 // Method java/lang/Number.intValue:()I
      84: aload_1
      85: iload_3
      86: iconst_1
      87: isub
      88: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      93: checkcast     #72                 // class java/util/List
      96: iload         5
      98: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     103: checkcast     #90                 // class java/lang/Number
     106: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     109: if_icmpge     321
     112: iload_3
     113: aload_1
     114: invokeinterface #158,  1          // InterfaceMethod java/util/List.size:()I
     119: iconst_1
     120: isub
     121: if_icmpeq     175
     124: aload_1
     125: iload_3
     126: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     131: checkcast     #72                 // class java/util/List
     134: iload         5
     136: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     141: checkcast     #90                 // class java/lang/Number
     144: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     147: aload_1
     148: iload_3
     149: iconst_1
     150: iadd
     151: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     156: checkcast     #72                 // class java/util/List
     159: iload         5
     161: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     166: checkcast     #90                 // class java/lang/Number
     169: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     172: if_icmpge     321
     175: iload         5
     177: ifeq          231
     180: aload_1
     181: iload_3
     182: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     187: checkcast     #72                 // class java/util/List
     190: iload         5
     192: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     197: checkcast     #90                 // class java/lang/Number
     200: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     203: aload_1
     204: iload_3
     205: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     210: checkcast     #72                 // class java/util/List
     213: iload         5
     215: iconst_1
     216: isub
     217: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     222: checkcast     #90                 // class java/lang/Number
     225: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     228: if_icmpge     321
     231: iload         5
     233: aload_1
     234: iconst_0
     235: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     240: checkcast     #72                 // class java/util/List
     243: invokeinterface #158,  1          // InterfaceMethod java/util/List.size:()I
     248: iconst_1
     249: isub
     250: if_icmpeq     304
     253: aload_1
     254: iload_3
     255: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     260: checkcast     #72                 // class java/util/List
     263: iload         5
     265: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     270: checkcast     #90                 // class java/lang/Number
     273: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     276: aload_1
     277: iload_3
     278: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     283: checkcast     #72                 // class java/util/List
     286: iload         5
     288: iconst_1
     289: iadd
     290: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     295: checkcast     #90                 // class java/lang/Number
     298: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     301: if_icmpge     321
     304: aload_2
     305: new           #78                 // class org/aoc2021/Day9$Point
     308: dup
     309: iload_3
     310: iload         5
     312: invokespecial #214                // Method org/aoc2021/Day9$Point."<init>":(II)V
     315: invokeinterface #142,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     320: pop
     321: iinc          5, 1
     324: goto          50
     327: iinc          3, 1
     330: goto          24
     333: aload_2
     334: checkcast     #15                 // class java/lang/Iterable
     337: invokestatic  #217                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     340: areturn

  private final java.lang.Integer[][] findBasins(java.util.List<? extends java.util.List<java.lang.Integer>>, java.util.List<org.aoc2021.Day9$Point>);
    Code:
       0: iconst_0
       1: istore        4
       3: aload_1
       4: invokeinterface #158,  1          // InterfaceMethod java/util/List.size:()I
       9: istore        5
      11: iload         5
      13: anewarray     #222                // class "[Ljava/lang/Integer;"
      16: astore        6
      18: iload         4
      20: iload         5
      22: if_icmpge     103
      25: iload         4
      27: istore        7
      29: aload         6
      31: iload         7
      33: iconst_0
      34: istore        8
      36: aload_1
      37: iconst_0
      38: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      43: checkcast     #72                 // class java/util/List
      46: invokeinterface #158,  1          // InterfaceMethod java/util/List.size:()I
      51: istore        9
      53: iload         9
      55: anewarray     #62                 // class java/lang/Integer
      58: astore        10
      60: istore        15
      62: astore        14
      64: iload         8
      66: iload         9
      68: if_icmpge     90
      71: iload         8
      73: istore        11
      75: aload         10
      77: iload         11
      79: iconst_0
      80: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      83: aastore
      84: iinc          8, 1
      87: goto          64
      90: aload         14
      92: iload         15
      94: aload         10
      96: aastore
      97: iinc          4, 1
     100: goto          18
     103: aload         6
     105: astore_3
     106: aload_2
     107: checkcast     #15                 // class java/lang/Iterable
     110: astore        4
     112: iconst_0
     113: istore        5
     115: iconst_0
     116: istore        6
     118: aload         4
     120: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     125: astore        7
     127: aload         7
     129: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     134: ifeq          198
     137: aload         7
     139: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     144: astore        8
     146: iload         6
     148: iinc          6, 1
     151: istore        9
     153: iload         9
     155: ifge          161
     158: invokestatic  #225                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     161: iload         9
     163: aload         8
     165: checkcast     #78                 // class org/aoc2021/Day9$Point
     168: astore        10
     170: istore        11
     172: iconst_0
     173: istore        12
     175: iload         11
     177: iconst_1
     178: iadd
     179: istore        13
     181: getstatic     #228                // Field INSTANCE:Lorg/aoc2021/Day9;
     184: aload         10
     186: iload         13
     188: aload_1
     189: aload_3
     190: invokespecial #232                // Method fill:(Lorg/aoc2021/Day9$Point;ILjava/util/List;[[Ljava/lang/Integer;)V
     193: nop
     194: nop
     195: goto          127
     198: nop
     199: aload_3
     200: areturn

  private final void fill(org.aoc2021.Day9$Point, int, java.util.List<? extends java.util.List<java.lang.Integer>>, java.lang.Integer[][]);
    Code:
       0: aload_1
       1: invokevirtual #243                // Method org/aoc2021/Day9$Point.component1:()I
       4: istore        5
       6: aload_1
       7: invokevirtual #246                // Method org/aoc2021/Day9$Point.component2:()I
      10: istore        6
      12: aload         4
      14: iload         5
      16: aaload
      17: iload         6
      19: iload_2
      20: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: aastore
      24: iconst_4
      25: anewarray     #248                // class kotlin/Pair
      28: astore        7
      30: aload         7
      32: iconst_0
      33: iconst_m1
      34: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: iconst_0
      38: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokestatic  #254                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      44: aastore
      45: aload         7
      47: iconst_1
      48: iconst_1
      49: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: iconst_0
      53: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      56: invokestatic  #254                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      59: aastore
      60: aload         7
      62: iconst_2
      63: iconst_0
      64: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: iconst_m1
      68: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      71: invokestatic  #254                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      74: aastore
      75: aload         7
      77: iconst_3
      78: iconst_0
      79: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      82: iconst_1
      83: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: invokestatic  #254                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      89: aastore
      90: aload         7
      92: invokestatic  #258                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      95: checkcast     #15                 // class java/lang/Iterable
      98: astore        7
     100: nop
     101: iconst_0
     102: istore        8
     104: aload         7
     106: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     111: astore        9
     113: aload         9
     115: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     120: ifeq          292
     123: aload         9
     125: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     130: astore        10
     132: aload         10
     134: checkcast     #248                // class kotlin/Pair
     137: astore        11
     139: iconst_0
     140: istore        12
     142: aload         11
     144: invokevirtual #260                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     147: checkcast     #90                 // class java/lang/Number
     150: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     153: istore        13
     155: aload         11
     157: invokevirtual #262                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     160: checkcast     #90                 // class java/lang/Number
     163: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     166: istore        14
     168: iload         5
     170: iload         13
     172: iadd
     173: istore        15
     175: iload         6
     177: iload         14
     179: iadd
     180: istore        16
     182: iload         15
     184: iflt          287
     187: iload         15
     189: aload_3
     190: invokeinterface #158,  1          // InterfaceMethod java/util/List.size:()I
     195: if_icmpge     287
     198: iload         16
     200: iflt          287
     203: iload         16
     205: aload_3
     206: iconst_0
     207: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     212: checkcast     #72                 // class java/util/List
     215: invokeinterface #158,  1          // InterfaceMethod java/util/List.size:()I
     220: if_icmpge     287
     223: aload_3
     224: iload         15
     226: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     231: checkcast     #72                 // class java/util/List
     234: iload         16
     236: invokeinterface #85,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     241: checkcast     #90                 // class java/lang/Number
     244: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     247: bipush        9
     249: if_icmpeq     287
     252: aload         4
     254: iload         15
     256: aaload
     257: iload         16
     259: aaload
     260: invokevirtual #263                // Method java/lang/Integer.intValue:()I
     263: ifne          287
     266: getstatic     #228                // Field INSTANCE:Lorg/aoc2021/Day9;
     269: new           #78                 // class org/aoc2021/Day9$Point
     272: dup
     273: iload         15
     275: iload         16
     277: invokespecial #214                // Method org/aoc2021/Day9$Point."<init>":(II)V
     280: iload_2
     281: aload_3
     282: aload         4
     284: invokespecial #232                // Method fill:(Lorg/aoc2021/Day9$Point;ILjava/util/List;[[Ljava/lang/Integer;)V
     287: nop
     288: nop
     289: goto          113
     292: nop
     293: return

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc_w         #277                // String args
       4: invokestatic  #283                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: ldc_w         #285                // String input9.txt
      10: iconst_0
      11: anewarray     #44                 // class java/lang/String
      14: invokestatic  #291                // InterfaceMethod java/nio/file/Path.of:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      17: getstatic     #297                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      20: invokestatic  #303                // Method java/nio/file/Files.readAllLines:(Ljava/nio/file/Path;Ljava/nio/charset/Charset;)Ljava/util/List;
      23: astore_1
      24: getstatic     #228                // Field INSTANCE:Lorg/aoc2021/Day9;
      27: aload_1
      28: invokestatic  #307                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      31: aload_1
      32: invokespecial #309                // Method solvePart1:(Ljava/util/List;)I
      35: istore_2
      36: getstatic     #315                // Field java/lang/System.out:Ljava/io/PrintStream;
      39: iload_2
      40: invokevirtual #320                // Method java/io/PrintStream.println:(I)V
      43: getstatic     #228                // Field INSTANCE:Lorg/aoc2021/Day9;
      46: aload_1
      47: invokespecial #322                // Method solvePart2:(Ljava/util/List;)I
      50: istore_3
      51: getstatic     #315                // Field java/lang/System.out:Ljava/io/PrintStream;
      54: iload_3
      55: invokevirtual #320                // Method java/io/PrintStream.println:(I)V
      58: return

  static {};
    Code:
       0: new           #2                  // class org/aoc2021/Day9
       3: dup
       4: invokespecial #327                // Method "<init>":()V
       7: putstatic     #228                // Field INSTANCE:Lorg/aoc2021/Day9;
      10: return
}