fun main() = Path.solve()

private typealias Matrix = List<List<Int>>

private object Path {
    const val START = 0
    const val TARGET = ('z'.code - 'a'.code) + 1

    fun solve() {
        val input = readInput()
        val starts = findAll(input, START)
        val target = findAll(input, TARGET).first()
        val graph = buildGraph(input)
        println("Shorted max elevation path: ${starts.map { shortestPath(graph, it, target) }.filter { it > 0 }.min()}")
    }

    private fun readInput(): Matrix {
        return generateSequence(::readLine).map {
            it.splitToSequence("").filter { !it.isEmpty() }.map {
                when (val char = it.first()) {
                    in 'a'..'z' -> char.code - 'a'.code
                    'S' -> START
                    'E' -> TARGET
                    else -> throw Error("Unexpected input char $char")
                }
            }.toList()
        }.toList()
    }

    private fun findAll(matrix: Matrix, target: Int): List<Pos> {
        val result = mutableListOf<Pos>()
        for (y in matrix.indices) {
            for (x in matrix[y].indices) {
                if (matrix[y][x] == target) {
                    result.add(Pos(x, y))
                }
            }
        }
        return result
    }

    private fun buildGraph(matrix: Matrix): Map<Pos, Node> {
        val height = matrix.size
        val width = matrix.first().size
        fun neighbours(pos: Pos) = listOf(
            Pos(pos.x - 1, pos.y),
            Pos(pos.x + 1, pos.y),
            Pos(pos.x, pos.y - 1),
            Pos(pos.x, pos.y + 1)
        ).filter { it.x in 0 until width && it.y in 0 until height }

        val result = mutableMapOf<Pos, Node>()
        for (y in matrix.indices) {
            for (x in matrix[y].indices) {
                val pos = Pos(x, y)
                val node = result.getOrPut(pos) { Node(pos, matrix[y][x]) }
                for (nPos in neighbours(pos)) {
                    val nNode = result.getOrPut(nPos) { Node(nPos, matrix[nPos.y][nPos.x]) }
                    if (nNode.height <= node.height + 1) {
                        node.edges.add(nPos)
                    }
                }
            }
        }
        return result
    }

    private fun shortestPath(graph: Map<Pos, Node>, start: Pos, target: Pos): Int {
        val paths = mutableMapOf<Pos, Int>()
        val queue = mutableListOf(Pair(start, 0))
        while (queue.size > 0) {
            val (pos, pathLen) = queue.removeAt(0)
            if (pos in paths) continue
            paths[pos] = pathLen
            for (edge in graph[pos]!!.edges) {
                if (edge in paths) continue
                if (edge == target) {
                    return pathLen + 1
                }
                queue.add(Pair(edge, pathLen + 1))
            }
        }
        return -1
    }

    data class Pos(val x: Int, val y: Int)

    data class Node(val pos: Pos, val height: Int, val edges: MutableList<Pos> = mutableListOf())
}

Compiled from "Path.kt"
public final class Path$Pos {
  private final int x;

  private final int y;

  public Path$Pos(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 Path$Pos copy(int, int);
    Code:
       0: new           #2                  // class Path$Pos
       3: dup
       4: iload_1
       5: iload_2
       6: invokespecial #28                 // Method "<init>":(II)V
       9: areturn

  public static Path$Pos copy$default(Path$Pos, 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)LPath$Pos;
      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 Pos(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 Path$Pos
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Path$Pos
      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 "Path.kt"
public final class Path$Node {
  private final Path$Pos pos;

  private final int height;

  private final java.util.List<Path$Pos> edges;

  public Path$Node(Path$Pos, int, java.util.List<Path$Pos>);
    Code:
       0: aload_1
       1: ldc           #10                 // String pos
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #18                 // String edges
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #21                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #24                 // Field pos:LPath$Pos;
      21: aload_0
      22: iload_2
      23: putfield      #28                 // Field height:I
      26: aload_0
      27: aload_3
      28: putfield      #31                 // Field edges:Ljava/util/List;
      31: return

  public Path$Node(Path$Pos, int, java.util.List, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         4
       2: iconst_4
       3: iand
       4: ifeq          18
       7: new           #36                 // class java/util/ArrayList
      10: dup
      11: invokespecial #37                 // Method java/util/ArrayList."<init>":()V
      14: checkcast     #39                 // class java/util/List
      17: astore_3
      18: aload_0
      19: aload_1
      20: iload_2
      21: aload_3
      22: invokespecial #41                 // Method "<init>":(LPath$Pos;ILjava/util/List;)V
      25: return

  public final Path$Pos getPos();
    Code:
       0: aload_0
       1: getfield      #24                 // Field pos:LPath$Pos;
       4: areturn

  public final int getHeight();
    Code:
       0: aload_0
       1: getfield      #28                 // Field height:I
       4: ireturn

  public final java.util.List<Path$Pos> getEdges();
    Code:
       0: aload_0
       1: getfield      #31                 // Field edges:Ljava/util/List;
       4: areturn

  public final Path$Pos component1();
    Code:
       0: aload_0
       1: getfield      #24                 // Field pos:LPath$Pos;
       4: areturn

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

  public final java.util.List<Path$Pos> component3();
    Code:
       0: aload_0
       1: getfield      #31                 // Field edges:Ljava/util/List;
       4: areturn

  public final Path$Node copy(Path$Pos, int, java.util.List<Path$Pos>);
    Code:
       0: aload_1
       1: ldc           #10                 // String pos
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #18                 // String edges
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class Path$Node
      15: dup
      16: aload_1
      17: iload_2
      18: aload_3
      19: invokespecial #41                 // Method "<init>":(LPath$Pos;ILjava/util/List;)V
      22: areturn

  public static Path$Node copy$default(Path$Node, Path$Pos, int, java.util.List, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #24                 // Field pos:LPath$Pos;
      11: astore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #28                 // Field height:I
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #31                 // Field edges:Ljava/util/List;
      35: astore_3
      36: aload_0
      37: aload_1
      38: iload_2
      39: aload_3
      40: invokevirtual #58                 // Method copy:(LPath$Pos;ILjava/util/List;)LPath$Node;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #62                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #63                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #65                 // String Node(pos=
       9: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #24                 // Field pos:LPath$Pos;
      16: invokevirtual #72                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #74                 // String , height=
      21: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #28                 // Field height:I
      28: invokevirtual #77                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #79                 // String , edges=
      33: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #31                 // Field edges:Ljava/util/List;
      40: invokevirtual #72                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #82                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #84                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #24                 // Field pos:LPath$Pos;
       4: invokevirtual #89                 // Method Path$Pos.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #28                 // Field height:I
      16: invokestatic  #94                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #31                 // Field edges:Ljava/util/List;
      29: invokevirtual #95                 // Method java/lang/Object.hashCode:()I
      32: iadd
      33: istore_1
      34: iload_1
      35: 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 Path$Node
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Path$Node
      20: astore_2
      21: aload_0
      22: getfield      #24                 // Field pos:LPath$Pos;
      25: aload_2
      26: getfield      #24                 // Field pos:LPath$Pos;
      29: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #28                 // Field height:I
      41: aload_2
      42: getfield      #28                 // Field height:I
      45: if_icmpeq     50
      48: iconst_0
      49: ireturn
      50: aload_0
      51: getfield      #31                 // Field edges:Ljava/util/List;
      54: aload_2
      55: getfield      #31                 // Field edges:Ljava/util/List;
      58: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      61: ifne          66
      64: iconst_0
      65: ireturn
      66: iconst_1
      67: ireturn
}

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

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

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

  public static final int START;

  public static final int TARGET;

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

  public final void solve();
    Code:
       0: aload_0
       1: invokespecial #15                 // Method readInput:()Ljava/util/List;
       4: astore_1
       5: aload_0
       6: aload_1
       7: iconst_0
       8: invokespecial #19                 // Method findAll:(Ljava/util/List;I)Ljava/util/List;
      11: astore_2
      12: aload_0
      13: aload_1
      14: bipush        26
      16: invokespecial #19                 // Method findAll:(Ljava/util/List;I)Ljava/util/List;
      19: invokestatic  #25                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      22: checkcast     #27                 // class Path$Pos
      25: astore_3
      26: aload_0
      27: aload_1
      28: invokespecial #31                 // Method buildGraph:(Ljava/util/List;)Ljava/util/Map;
      31: astore        4
      33: new           #33                 // class java/lang/StringBuilder
      36: dup
      37: invokespecial #34                 // Method java/lang/StringBuilder."<init>":()V
      40: ldc           #36                 // String Shorted max elevation path:
      42: invokevirtual #40                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      45: aload_2
      46: checkcast     #42                 // class java/lang/Iterable
      49: astore        5
      51: astore        14
      53: iconst_0
      54: istore        6
      56: aload         5
      58: astore        7
      60: new           #44                 // class java/util/ArrayList
      63: dup
      64: aload         5
      66: bipush        10
      68: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      71: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
      74: checkcast     #53                 // class java/util/Collection
      77: astore        8
      79: iconst_0
      80: istore        9
      82: aload         7
      84: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      89: astore        10
      91: aload         10
      93: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      98: ifeq          150
     101: aload         10
     103: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     108: astore        11
     110: aload         8
     112: aload         11
     114: checkcast     #27                 // class Path$Pos
     117: astore        12
     119: astore        15
     121: iconst_0
     122: istore        13
     124: getstatic     #70                 // Field INSTANCE:LPath;
     127: aload         4
     129: aload         12
     131: aload_3
     132: invokespecial #74                 // Method shortestPath:(Ljava/util/Map;LPath$Pos;LPath$Pos;)I
     135: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: aload         15
     140: swap
     141: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     146: pop
     147: goto          91
     150: aload         8
     152: checkcast     #86                 // class java/util/List
     155: nop
     156: aload         14
     158: swap
     159: checkcast     #42                 // class java/lang/Iterable
     162: astore        5
     164: astore        14
     166: iconst_0
     167: istore        6
     169: aload         5
     171: astore        7
     173: new           #44                 // class java/util/ArrayList
     176: dup
     177: invokespecial #87                 // Method java/util/ArrayList."<init>":()V
     180: checkcast     #53                 // class java/util/Collection
     183: astore        8
     185: iconst_0
     186: istore        9
     188: aload         7
     190: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     195: astore        10
     197: aload         10
     199: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     204: ifeq          255
     207: aload         10
     209: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     214: astore        11
     216: aload         11
     218: checkcast     #89                 // class java/lang/Number
     221: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     224: istore        12
     226: iconst_0
     227: istore        13
     229: iload         12
     231: ifle          238
     234: iconst_1
     235: goto          239
     238: iconst_0
     239: ifeq          197
     242: aload         8
     244: aload         11
     246: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     251: pop
     252: goto          197
     255: aload         8
     257: checkcast     #86                 // class java/util/List
     260: nop
     261: aload         14
     263: swap
     264: checkcast     #42                 // class java/lang/Iterable
     267: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     270: checkcast     #89                 // class java/lang/Number
     273: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     276: invokevirtual #100                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     279: invokevirtual #104                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     282: getstatic     #110                // Field java/lang/System.out:Ljava/io/PrintStream;
     285: swap
     286: invokevirtual #116                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     289: return

  private final java.util.List<java.util.List<java.lang.Integer>> readInput();
    Code:
       0: getstatic     #149                // Field Path$readInput$1.INSTANCE:LPath$readInput$1;
       3: checkcast     #151                // class kotlin/jvm/functions/Function0
       6: invokestatic  #157                // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
       9: invokedynamic #176,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      14: invokestatic  #180                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      17: invokestatic  #184                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      20: areturn

  private final java.util.List<Path$Pos> findAll(java.util.List<? extends java.util.List<java.lang.Integer>>, int);
    Code:
       0: new           #44                 // class java/util/ArrayList
       3: dup
       4: invokespecial #87                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #86                 // class java/util/List
      10: astore_3
      11: iconst_0
      12: istore        4
      14: aload_1
      15: checkcast     #53                 // class java/util/Collection
      18: invokeinterface #188,  1          // InterfaceMethod java/util/Collection.size:()I
      23: istore        5
      25: iload         4
      27: iload         5
      29: if_icmpge     118
      32: iconst_0
      33: istore        6
      35: aload_1
      36: iload         4
      38: invokeinterface #192,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      43: checkcast     #53                 // class java/util/Collection
      46: invokeinterface #188,  1          // InterfaceMethod java/util/Collection.size:()I
      51: istore        7
      53: iload         6
      55: iload         7
      57: if_icmpge     112
      60: aload_1
      61: iload         4
      63: invokeinterface #192,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #86                 // class java/util/List
      71: iload         6
      73: invokeinterface #192,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      78: checkcast     #89                 // class java/lang/Number
      81: invokevirtual #93                 // Method java/lang/Number.intValue:()I
      84: iload_2
      85: if_icmpne     106
      88: aload_3
      89: new           #27                 // class Path$Pos
      92: dup
      93: iload         6
      95: iload         4
      97: invokespecial #195                // Method Path$Pos."<init>":(II)V
     100: invokeinterface #196,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     105: pop
     106: iinc          6, 1
     109: goto          53
     112: iinc          4, 1
     115: goto          25
     118: aload_3
     119: areturn

  private final java.util.Map<Path$Pos, Path$Node> buildGraph(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: aload_1
       1: invokeinterface #202,  1          // InterfaceMethod java/util/List.size:()I
       6: istore_2
       7: aload_1
       8: invokestatic  #25                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      11: checkcast     #86                 // class java/util/List
      14: invokeinterface #202,  1          // InterfaceMethod java/util/List.size:()I
      19: istore_3
      20: new           #204                // class java/util/LinkedHashMap
      23: dup
      24: invokespecial #205                // Method java/util/LinkedHashMap."<init>":()V
      27: checkcast     #143                // class java/util/Map
      30: astore        4
      32: iconst_0
      33: istore        5
      35: aload_1
      36: checkcast     #53                 // class java/util/Collection
      39: invokeinterface #188,  1          // InterfaceMethod java/util/Collection.size:()I
      44: istore        6
      46: iload         5
      48: iload         6
      50: if_icmpge     357
      53: iconst_0
      54: istore        7
      56: aload_1
      57: iload         5
      59: invokeinterface #192,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      64: checkcast     #53                 // class java/util/Collection
      67: invokeinterface #188,  1          // InterfaceMethod java/util/Collection.size:()I
      72: istore        8
      74: iload         7
      76: iload         8
      78: if_icmpge     351
      81: new           #27                 // class Path$Pos
      84: dup
      85: iload         7
      87: iload         5
      89: invokespecial #195                // Method Path$Pos."<init>":(II)V
      92: astore        9
      94: aload         4
      96: astore        11
      98: iconst_0
      99: istore        12
     101: aload         11
     103: aload         9
     105: invokeinterface #207,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     110: astore        13
     112: aload         13
     114: ifnonnull     175
     117: iconst_0
     118: istore        14
     120: new           #209                // class Path$Node
     123: dup
     124: aload         9
     126: aload_1
     127: iload         5
     129: invokeinterface #192,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #86                 // class java/util/List
     137: iload         7
     139: invokeinterface #192,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     144: checkcast     #89                 // class java/lang/Number
     147: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     150: aconst_null
     151: iconst_4
     152: aconst_null
     153: invokespecial #212                // Method Path$Node."<init>":(LPath$Pos;ILjava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     156: astore        15
     158: aload         11
     160: aload         9
     162: aload         15
     164: invokeinterface #216,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     169: pop
     170: aload         15
     172: goto          177
     175: aload         13
     177: nop
     178: checkcast     #209                // class Path$Node
     181: astore        10
     183: iload_3
     184: iload_2
     185: aload         9
     187: invokestatic  #220                // Method buildGraph$neighbours:(IILPath$Pos;)Ljava/util/List;
     190: invokeinterface #221,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     195: astore        11
     197: aload         11
     199: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     204: ifeq          345
     207: aload         11
     209: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     214: checkcast     #27                 // class Path$Pos
     217: astore        12
     219: aload         4
     221: astore        14
     223: iconst_0
     224: istore        15
     226: aload         14
     228: aload         12
     230: invokeinterface #207,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     235: astore        16
     237: aload         16
     239: ifnonnull     306
     242: iconst_0
     243: istore        17
     245: new           #209                // class Path$Node
     248: dup
     249: aload         12
     251: aload_1
     252: aload         12
     254: invokevirtual #224                // Method Path$Pos.getY:()I
     257: invokeinterface #192,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     262: checkcast     #86                 // class java/util/List
     265: aload         12
     267: invokevirtual #227                // Method Path$Pos.getX:()I
     270: invokeinterface #192,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     275: checkcast     #89                 // class java/lang/Number
     278: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     281: aconst_null
     282: iconst_4
     283: aconst_null
     284: invokespecial #212                // Method Path$Node."<init>":(LPath$Pos;ILjava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     287: astore        18
     289: aload         14
     291: aload         12
     293: aload         18
     295: invokeinterface #216,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     300: pop
     301: aload         18
     303: goto          308
     306: aload         16
     308: nop
     309: checkcast     #209                // class Path$Node
     312: astore        13
     314: aload         13
     316: invokevirtual #230                // Method Path$Node.getHeight:()I
     319: aload         10
     321: invokevirtual #230                // Method Path$Node.getHeight:()I
     324: iconst_1
     325: iadd
     326: if_icmpgt     197
     329: aload         10
     331: invokevirtual #233                // Method Path$Node.getEdges:()Ljava/util/List;
     334: aload         12
     336: invokeinterface #196,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     341: pop
     342: goto          197
     345: iinc          7, 1
     348: goto          74
     351: iinc          5, 1
     354: goto          46
     357: aload         4
     359: areturn

  private final int shortestPath(java.util.Map<Path$Pos, Path$Node>, Path$Pos, Path$Pos);
    Code:
       0: new           #204                // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #205                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #143                // class java/util/Map
      10: astore        4
      12: iconst_1
      13: anewarray     #249                // class kotlin/Pair
      16: astore        6
      18: aload         6
      20: iconst_0
      21: new           #249                // class kotlin/Pair
      24: dup
      25: aload_2
      26: iconst_0
      27: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      30: invokespecial #252                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      33: aastore
      34: aload         6
      36: invokestatic  #256                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      39: astore        5
      41: aload         5
      43: invokeinterface #202,  1          // InterfaceMethod java/util/List.size:()I
      48: ifle          218
      51: aload         5
      53: iconst_0
      54: invokeinterface #259,  2          // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
      59: checkcast     #249                // class kotlin/Pair
      62: astore        6
      64: aload         6
      66: invokevirtual #262                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      69: checkcast     #27                 // class Path$Pos
      72: astore        7
      74: aload         6
      76: invokevirtual #265                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      79: checkcast     #89                 // class java/lang/Number
      82: invokevirtual #93                 // Method java/lang/Number.intValue:()I
      85: istore        8
      87: aload         4
      89: aload         7
      91: invokeinterface #268,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      96: ifne          41
      99: iload         8
     101: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: astore        10
     106: aload         4
     108: aload         7
     110: aload         10
     112: invokeinterface #216,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     117: pop
     118: aload_1
     119: aload         7
     121: invokeinterface #207,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     126: dup
     127: invokestatic  #273                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     130: checkcast     #209                // class Path$Node
     133: invokevirtual #233                // Method Path$Node.getEdges:()Ljava/util/List;
     136: invokeinterface #221,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     141: astore        9
     143: aload         9
     145: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifeq          41
     153: aload         9
     155: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     160: checkcast     #27                 // class Path$Pos
     163: astore        10
     165: aload         4
     167: aload         10
     169: invokeinterface #268,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     174: ifne          143
     177: aload         10
     179: aload_3
     180: invokestatic  #277                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     183: ifeq          191
     186: iload         8
     188: iconst_1
     189: iadd
     190: ireturn
     191: aload         5
     193: new           #249                // class kotlin/Pair
     196: dup
     197: aload         10
     199: iload         8
     201: iconst_1
     202: iadd
     203: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     206: invokespecial #252                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     209: invokeinterface #196,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     214: pop
     215: goto          143
     218: iconst_m1
     219: ireturn

  private static final boolean readInput$lambda$4$lambda$2(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #285                // String it
       4: invokestatic  #289                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #291                // class java/lang/CharSequence
      11: invokeinterface #294,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      16: ifne          23
      19: iconst_1
      20: goto          24
      23: iconst_0
      24: ifne          31
      27: iconst_1
      28: goto          32
      31: iconst_0
      32: ireturn

  private static final int readInput$lambda$4$lambda$3(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #285                // String it
       4: invokestatic  #289                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #291                // class java/lang/CharSequence
      11: invokestatic  #302                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
      14: istore_1
      15: bipush        97
      17: iload_1
      18: if_icmpgt     35
      21: iload_1
      22: bipush        123
      24: if_icmpge     31
      27: iconst_1
      28: goto          36
      31: iconst_0
      32: goto          36
      35: iconst_0
      36: ifeq          46
      39: iload_1
      40: bipush        97
      42: isub
      43: goto          95
      46: iload_1
      47: bipush        83
      49: if_icmpne     56
      52: iconst_0
      53: goto          95
      56: iload_1
      57: bipush        69
      59: if_icmpne     67
      62: bipush        26
      64: goto          95
      67: new           #304                // class java/lang/Error
      70: dup
      71: new           #33                 // class java/lang/StringBuilder
      74: dup
      75: invokespecial #34                 // Method java/lang/StringBuilder."<init>":()V
      78: ldc_w         #306                // String Unexpected input char
      81: invokevirtual #40                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      84: iload_1
      85: invokevirtual #309                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      88: invokevirtual #104                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      91: invokespecial #312                // Method java/lang/Error."<init>":(Ljava/lang/String;)V
      94: athrow
      95: ireturn

  private static final java.util.List readInput$lambda$4(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #285                // String it
       4: invokestatic  #289                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #291                // class java/lang/CharSequence
      11: iconst_1
      12: anewarray     #316                // class java/lang/String
      15: astore_1
      16: aload_1
      17: iconst_0
      18: ldc_w         #318                // String
      21: aastore
      22: aload_1
      23: iconst_0
      24: iconst_0
      25: bipush        6
      27: aconst_null
      28: invokestatic  #322                // Method kotlin/text/StringsKt.splitToSequence$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Lkotlin/sequences/Sequence;
      31: invokedynamic #328,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      36: invokestatic  #331                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      39: invokedynamic #337,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
      44: invokestatic  #180                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      47: invokestatic  #184                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      50: areturn

  private static final java.util.List<Path$Pos> buildGraph$neighbours(int, int, Path$Pos);
    Code:
       0: iconst_4
       1: anewarray     #27                 // class Path$Pos
       4: astore_3
       5: aload_3
       6: iconst_0
       7: new           #27                 // class Path$Pos
      10: dup
      11: aload_2
      12: invokevirtual #227                // Method Path$Pos.getX:()I
      15: iconst_1
      16: isub
      17: aload_2
      18: invokevirtual #224                // Method Path$Pos.getY:()I
      21: invokespecial #195                // Method Path$Pos."<init>":(II)V
      24: aastore
      25: aload_3
      26: iconst_1
      27: new           #27                 // class Path$Pos
      30: dup
      31: aload_2
      32: invokevirtual #227                // Method Path$Pos.getX:()I
      35: iconst_1
      36: iadd
      37: aload_2
      38: invokevirtual #224                // Method Path$Pos.getY:()I
      41: invokespecial #195                // Method Path$Pos."<init>":(II)V
      44: aastore
      45: aload_3
      46: iconst_2
      47: new           #27                 // class Path$Pos
      50: dup
      51: aload_2
      52: invokevirtual #227                // Method Path$Pos.getX:()I
      55: aload_2
      56: invokevirtual #224                // Method Path$Pos.getY:()I
      59: iconst_1
      60: isub
      61: invokespecial #195                // Method Path$Pos."<init>":(II)V
      64: aastore
      65: aload_3
      66: iconst_3
      67: new           #27                 // class Path$Pos
      70: dup
      71: aload_2
      72: invokevirtual #227                // Method Path$Pos.getX:()I
      75: aload_2
      76: invokevirtual #224                // Method Path$Pos.getY:()I
      79: iconst_1
      80: iadd
      81: invokespecial #195                // Method Path$Pos."<init>":(II)V
      84: aastore
      85: aload_3
      86: invokestatic  #341                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      89: checkcast     #42                 // class java/lang/Iterable
      92: astore_3
      93: nop
      94: iconst_0
      95: istore        4
      97: aload_3
      98: astore        5
     100: new           #44                 // class java/util/ArrayList
     103: dup
     104: invokespecial #87                 // Method java/util/ArrayList."<init>":()V
     107: checkcast     #53                 // class java/util/Collection
     110: astore        6
     112: iconst_0
     113: istore        7
     115: aload         5
     117: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     122: astore        8
     124: aload         8
     126: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     131: ifeq          236
     134: aload         8
     136: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     141: astore        9
     143: aload         9
     145: checkcast     #27                 // class Path$Pos
     148: astore        10
     150: iconst_0
     151: istore        11
     153: aload         10
     155: invokevirtual #227                // Method Path$Pos.getX:()I
     158: istore        12
     160: iconst_0
     161: iload         12
     163: if_icmpgt     180
     166: iload         12
     168: iload_0
     169: if_icmpge     176
     172: iconst_1
     173: goto          181
     176: iconst_0
     177: goto          181
     180: iconst_0
     181: ifeq          219
     184: aload         10
     186: invokevirtual #224                // Method Path$Pos.getY:()I
     189: istore        12
     191: iconst_0
     192: iload         12
     194: if_icmpgt     211
     197: iload         12
     199: iload_1
     200: if_icmpge     207
     203: iconst_1
     204: goto          212
     207: iconst_0
     208: goto          212
     211: iconst_0
     212: ifeq          219
     215: iconst_1
     216: goto          220
     219: iconst_0
     220: ifeq          124
     223: aload         6
     225: aload         9
     227: invokeinterface #84,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     232: pop
     233: goto          124
     236: aload         6
     238: checkcast     #86                 // class java/util/List
     241: nop
     242: areturn

  static {};
    Code:
       0: new           #2                  // class Path
       3: dup
       4: invokespecial #344                // Method "<init>":()V
       7: putstatic     #70                 // Field INSTANCE:LPath;
      10: return
}

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

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

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

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

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