package io.github.zebalu.advent2020

import java.math.BigInteger

object IdealTimeFinder {

	fun findTime2(buses: List<Pair<Int, Int>>): Long = longBuses(buses)
		.fold(Pair(0L, 1L)) { acc, next -> applyBus(acc.first, acc.second, next.first, next.second) }.first

	private fun applyBus(sum: Long, interval: Long, bus: Long, timeDif: Long) =
		Pair(findTimeWithRightDiff(sum, interval, timeDif, bus), interval * bus)

	private tailrec fun findTimeWithRightDiff(start: Long, interval: Long, expected: Long, bus: Long): Long =
		if ((start + expected) % bus == 0L) start
		else findTimeWithRightDiff(start + interval, interval, expected, bus)

	private fun longBuses(buses: List<Pair<Int, Int>>) = buses.map { Pair(it.first.toLong(), it.second.toLong()) }

	fun findTime(buses: List<Pair<Long, Long>>): Long {
		return chineseRemainder(buses)
	}

	/* returns x where (a * x) % b == 1 */
	fun multInv(a: Long, b: Long): Long {
		if (b == 1L) return 1L
		var aa = a
		var bb = b
		var x0 = 0L
		var x1 = 1L
		while (aa > 1) {
			x0 = (x1 - (aa / bb) * x0).also { x1 = x0 }
			bb = (aa % bb).also { aa = bb }
		}
		if (x1 < 0) x1 += b
		return x1
	}

	fun chineseRemainder(buses: List<Pair<Long, Long>>): Long {
		val prod = buses.map { it.first }.fold(1L) { acc, i -> acc * i }
		var sum = 0L
		for (i in buses.indices) {
			val p = prod / buses[i].first
			sum += buses[i].second * multInv(p, buses[i].first) * p
		}
		return sum % prod
	}
}

Compiled from "IdealTimeFinder.kt"
public final class io.github.zebalu.advent2020.IdealTimeFinder {
  public static final io.github.zebalu.advent2020.IdealTimeFinder INSTANCE;

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

  public final long findTime2(java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_1
       1: ldc           #16                 // String buses
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #26                 // Method longBuses:(Ljava/util/List;)Ljava/util/List;
      11: checkcast     #28                 // class java/lang/Iterable
      14: astore_2
      15: new           #30                 // class kotlin/Pair
      18: dup
      19: lconst_0
      20: invokestatic  #36                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      23: lconst_1
      24: invokestatic  #36                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      27: invokespecial #39                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      30: astore_3
      31: iconst_0
      32: istore        4
      34: aload_3
      35: astore        5
      37: aload_2
      38: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          133
      55: aload         6
      57: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         5
      66: aload         7
      68: checkcast     #30                 // class kotlin/Pair
      71: astore        8
      73: astore        9
      75: iconst_0
      76: istore        10
      78: getstatic     #56                 // Field INSTANCE:Lio/github/zebalu/advent2020/IdealTimeFinder;
      81: aload         9
      83: invokevirtual #59                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      86: checkcast     #61                 // class java/lang/Number
      89: invokevirtual #65                 // Method java/lang/Number.longValue:()J
      92: aload         9
      94: invokevirtual #68                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      97: checkcast     #61                 // class java/lang/Number
     100: invokevirtual #65                 // Method java/lang/Number.longValue:()J
     103: aload         8
     105: invokevirtual #59                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     108: checkcast     #61                 // class java/lang/Number
     111: invokevirtual #65                 // Method java/lang/Number.longValue:()J
     114: aload         8
     116: invokevirtual #68                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     119: checkcast     #61                 // class java/lang/Number
     122: invokevirtual #65                 // Method java/lang/Number.longValue:()J
     125: invokespecial #72                 // Method applyBus:(JJJJ)Lkotlin/Pair;
     128: astore        5
     130: goto          45
     133: aload         5
     135: invokevirtual #59                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     138: checkcast     #61                 // class java/lang/Number
     141: invokevirtual #65                 // Method java/lang/Number.longValue:()J
     144: lreturn

  private final kotlin.Pair<java.lang.Long, java.lang.Long> applyBus(long, long, long, long);
    Code:
       0: new           #30                 // class kotlin/Pair
       3: dup
       4: aload_0
       5: lload_1
       6: lload_3
       7: lload         7
       9: lload         5
      11: invokespecial #91                 // Method findTimeWithRightDiff:(JJJJ)J
      14: invokestatic  #36                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      17: lload_3
      18: lload         5
      20: lmul
      21: invokestatic  #36                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      24: invokespecial #39                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      27: areturn

  private final long findTimeWithRightDiff(long, long, long, long);
    Code:
       0: aload_0
       1: astore        9
       3: lload_1
       4: lload         5
       6: ladd
       7: lload         7
       9: lrem
      10: lconst_0
      11: lcmp
      12: ifne          19
      15: lload_1
      16: goto          60
      19: aload         9
      21: astore        10
      23: lload_1
      24: lload_3
      25: ladd
      26: lstore        11
      28: lload_3
      29: lstore        13
      31: lload         5
      33: lstore        15
      35: lload         7
      37: lstore        17
      39: aload         10
      41: astore        9
      43: lload         11
      45: lstore_1
      46: lload         13
      48: lstore_3
      49: lload         15
      51: lstore        5
      53: lload         17
      55: lstore        7
      57: goto          3
      60: lreturn

  private final java.util.List<kotlin.Pair<java.lang.Long, java.lang.Long>> longBuses(java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_1
       1: checkcast     #28                 // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #101                // class java/util/ArrayList
      13: dup
      14: aload_2
      15: bipush        10
      17: invokestatic  #107                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #110                // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #112                // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         4
      33: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          122
      50: aload         7
      52: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         5
      61: aload         8
      63: checkcast     #30                 // class kotlin/Pair
      66: astore        9
      68: astore        11
      70: iconst_0
      71: istore        10
      73: new           #30                 // class kotlin/Pair
      76: dup
      77: aload         9
      79: invokevirtual #59                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      82: checkcast     #61                 // class java/lang/Number
      85: invokevirtual #116                // Method java/lang/Number.intValue:()I
      88: i2l
      89: invokestatic  #36                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      92: aload         9
      94: invokevirtual #68                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      97: checkcast     #61                 // class java/lang/Number
     100: invokevirtual #116                // Method java/lang/Number.intValue:()I
     103: i2l
     104: invokestatic  #36                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     107: invokespecial #39                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     110: aload         11
     112: swap
     113: invokeinterface #120,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     118: pop
     119: goto          40
     122: aload         5
     124: checkcast     #86                 // class java/util/List
     127: nop
     128: areturn

  public final long findTime(java.util.List<kotlin.Pair<java.lang.Long, java.lang.Long>>);
    Code:
       0: aload_1
       1: ldc           #16                 // String buses
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokevirtual #134                // Method chineseRemainder:(Ljava/util/List;)J
      11: lreturn

  public final long multInv(long, long);
    Code:
       0: lload_3
       1: lconst_1
       2: lcmp
       3: ifne          8
       6: lconst_1
       7: lreturn
       8: lconst_0
       9: lstore        10
      11: lload_1
      12: lstore        10
      14: lconst_0
      15: lstore        12
      17: lload_3
      18: lstore        12
      20: lconst_0
      21: lstore        14
      23: lconst_0
      24: lstore        16
      26: lconst_1
      27: lstore        16
      29: lload         10
      31: lconst_1
      32: lcmp
      33: ifle          89
      36: lload         16
      38: lload         10
      40: lload         12
      42: ldiv
      43: lload         14
      45: lmul
      46: lsub
      47: lstore        5
      49: lload         5
      51: lstore        7
      53: iconst_0
      54: istore        9
      56: lload         14
      58: lstore        16
      60: lload         5
      62: lstore        14
      64: lload         10
      66: lload         12
      68: lrem
      69: lstore        5
      71: lload         5
      73: lstore        7
      75: iconst_0
      76: istore        9
      78: lload         12
      80: lstore        10
      82: lload         5
      84: lstore        12
      86: goto          29
      89: lload         16
      91: lconst_0
      92: lcmp
      93: ifge          102
      96: lload         16
      98: lload_3
      99: ladd
     100: lstore        16
     102: lload         16
     104: lreturn

  public final long chineseRemainder(java.util.List<kotlin.Pair<java.lang.Long, java.lang.Long>>);
    Code:
       0: aload_1
       1: ldc           #16                 // String buses
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #28                 // class java/lang/Iterable
      10: astore        4
      12: iconst_0
      13: istore        5
      15: aload         4
      17: astore        7
      19: new           #101                // class java/util/ArrayList
      22: dup
      23: aload         4
      25: bipush        10
      27: invokestatic  #107                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      30: invokespecial #110                // Method java/util/ArrayList."<init>":(I)V
      33: checkcast     #112                // class java/util/Collection
      36: astore        8
      38: iconst_0
      39: istore        10
      41: aload         7
      43: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        11
      50: aload         11
      52: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          109
      60: aload         11
      62: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        12
      69: aload         8
      71: aload         12
      73: checkcast     #30                 // class kotlin/Pair
      76: astore        13
      78: astore        17
      80: iconst_0
      81: istore        14
      83: aload         13
      85: invokevirtual #59                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      88: checkcast     #61                 // class java/lang/Number
      91: invokevirtual #65                 // Method java/lang/Number.longValue:()J
      94: invokestatic  #36                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      97: aload         17
      99: swap
     100: invokeinterface #120,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     105: pop
     106: goto          50
     109: aload         8
     111: checkcast     #86                 // class java/util/List
     114: nop
     115: checkcast     #28                 // class java/lang/Iterable
     118: astore        4
     120: lconst_1
     121: lstore        5
     123: iconst_0
     124: istore        7
     126: lload         5
     128: lstore        8
     130: aload         4
     132: invokeinterface #43,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     137: astore        10
     139: aload         10
     141: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     146: ifeq          185
     149: aload         10
     151: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     156: astore        11
     158: lload         8
     160: aload         11
     162: checkcast     #61                 // class java/lang/Number
     165: invokevirtual #65                 // Method java/lang/Number.longValue:()J
     168: lstore        12
     170: lstore        14
     172: iconst_0
     173: istore        16
     175: lload         14
     177: lload         12
     179: lmul
     180: lstore        8
     182: goto          139
     185: lload         8
     187: lstore_2
     188: lconst_0
     189: lstore        4
     191: iconst_0
     192: istore        7
     194: aload_1
     195: checkcast     #112                // class java/util/Collection
     198: invokeinterface #147,  1          // InterfaceMethod java/util/Collection.size:()I
     203: istore        8
     205: iload         7
     207: iload         8
     209: if_icmpge     297
     212: lload_2
     213: aload_1
     214: iload         7
     216: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     221: checkcast     #30                 // class kotlin/Pair
     224: invokevirtual #59                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     227: checkcast     #61                 // class java/lang/Number
     230: invokevirtual #65                 // Method java/lang/Number.longValue:()J
     233: ldiv
     234: lstore        10
     236: lload         4
     238: aload_1
     239: iload         7
     241: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     246: checkcast     #30                 // class kotlin/Pair
     249: invokevirtual #68                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     252: checkcast     #61                 // class java/lang/Number
     255: invokevirtual #65                 // Method java/lang/Number.longValue:()J
     258: aload_0
     259: lload         10
     261: aload_1
     262: iload         7
     264: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     269: checkcast     #30                 // class kotlin/Pair
     272: invokevirtual #59                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     275: checkcast     #61                 // class java/lang/Number
     278: invokevirtual #65                 // Method java/lang/Number.longValue:()J
     281: invokevirtual #153                // Method multInv:(JJ)J
     284: lmul
     285: lload         10
     287: lmul
     288: ladd
     289: lstore        4
     291: iinc          7, 1
     294: goto          205
     297: lload         4
     299: lload_2
     300: lrem
     301: lreturn

  static {};
    Code:
       0: new           #2                  // class io/github/zebalu/advent2020/IdealTimeFinder
       3: dup
       4: invokespecial #160                // Method "<init>":()V
       7: putstatic     #56                 // Field INSTANCE:Lio/github/zebalu/advent2020/IdealTimeFinder;
      10: return
}


package oct_challenge2021

fun main() {
    val trie = Trie()
    trie.insert("apple")
    val res1 = trie.search("apple")
    assert(res1)
    val res2 = trie.search("app")
    assert(!res2)
    val res3 = trie.startsWith("app")
    assert(res3)
    trie.insert("app")
    val res4 = trie.search("app")
    assert(res4)
}

class Trie {
    private val root: TrieNode? = TrieNode()

    fun insert(word: String) {
        var node = root
        for (currChar in word) {
            if (!node!!.containsKey(currChar)) {
                node.put(currChar, TrieNode())
            }
            node = node.get(currChar)
        }
        node!!.isEnd = true
    }

    fun search(word: String): Boolean {
        val node = searchPrefix(word)
        return node != null && node.isEnd
    }

    fun startsWith(prefix: String): Boolean {
        val node = searchPrefix(prefix)
        return node != null
    }

    private fun searchPrefix(word: String): TrieNode? {
        var node = root
        for (currChar in word) {
            if (node!!.containsKey(currChar)) {
                node = node.get(currChar)
            } else {
                return null
            }
        }

        return node
    }

}

private class TrieNode {
    private val numberOfAlphabet = 26
    private var links: Array<TrieNode?> = arrayOfNulls(numberOfAlphabet)
    var isEnd = false

    fun containsKey(char: Char): Boolean {
        return links[char - 'a'] != null
    }

    fun get(char: Char): TrieNode? {
        return links[char - 'a']
    }

    fun put(char: Char, node: TrieNode) {
        links[char - 'a'] = node
    }

}

Compiled from "Trie.kt"
public final class oct_challenge2021.Trie {
  private final oct_challenge2021.TrieNode root;

  public oct_challenge2021.Trie();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #10                 // class oct_challenge2021/TrieNode
       8: dup
       9: invokespecial #11                 // Method oct_challenge2021/TrieNode."<init>":()V
      12: putfield      #15                 // Field root:Loct_challenge2021/TrieNode;
      15: return

  public final void insert(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #22                 // String word
       3: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #15                 // Field root:Loct_challenge2021/TrieNode;
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_1
      14: invokevirtual #34                 // Method java/lang/String.length:()I
      17: istore        4
      19: iload_3
      20: iload         4
      22: if_icmpge     71
      25: aload_1
      26: iload_3
      27: invokevirtual #38                 // Method java/lang/String.charAt:(I)C
      30: istore        5
      32: aload_2
      33: dup
      34: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      37: iload         5
      39: invokevirtual #46                 // Method oct_challenge2021/TrieNode.containsKey:(C)Z
      42: ifne          58
      45: aload_2
      46: iload         5
      48: new           #10                 // class oct_challenge2021/TrieNode
      51: dup
      52: invokespecial #11                 // Method oct_challenge2021/TrieNode."<init>":()V
      55: invokevirtual #50                 // Method oct_challenge2021/TrieNode.put:(CLoct_challenge2021/TrieNode;)V
      58: aload_2
      59: iload         5
      61: invokevirtual #54                 // Method oct_challenge2021/TrieNode.get:(C)Loct_challenge2021/TrieNode;
      64: astore_2
      65: iinc          3, 1
      68: goto          19
      71: aload_2
      72: dup
      73: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      76: iconst_1
      77: invokevirtual #58                 // Method oct_challenge2021/TrieNode.setEnd:(Z)V
      80: return

  public final boolean search(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #22                 // String word
       3: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #68                 // Method searchPrefix:(Ljava/lang/String;)Loct_challenge2021/TrieNode;
      11: astore_2
      12: aload_2
      13: ifnull        27
      16: aload_2
      17: invokevirtual #72                 // Method oct_challenge2021/TrieNode.isEnd:()Z
      20: ifeq          27
      23: iconst_1
      24: goto          28
      27: iconst_0
      28: ireturn

  public final boolean startsWith(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #75                 // String prefix
       3: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #68                 // Method searchPrefix:(Ljava/lang/String;)Loct_challenge2021/TrieNode;
      11: astore_2
      12: aload_2
      13: ifnull        20
      16: iconst_1
      17: goto          21
      20: iconst_0
      21: ireturn

  private final oct_challenge2021.TrieNode searchPrefix(java.lang.String);
    Code:
       0: aload_0
       1: getfield      #15                 // Field root:Loct_challenge2021/TrieNode;
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_1
       8: invokevirtual #34                 // Method java/lang/String.length:()I
      11: istore        4
      13: iload_3
      14: iload         4
      16: if_icmpge     57
      19: aload_1
      20: iload_3
      21: invokevirtual #38                 // Method java/lang/String.charAt:(I)C
      24: istore        5
      26: aload_2
      27: dup
      28: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      31: iload         5
      33: invokevirtual #46                 // Method oct_challenge2021/TrieNode.containsKey:(C)Z
      36: ifeq          49
      39: aload_2
      40: iload         5
      42: invokevirtual #54                 // Method oct_challenge2021/TrieNode.get:(C)Loct_challenge2021/TrieNode;
      45: astore_2
      46: goto          51
      49: aconst_null
      50: areturn
      51: iinc          3, 1
      54: goto          13
      57: aload_2
      58: areturn
}

Compiled from "Trie.kt"
public final class oct_challenge2021.TrieKt {
  public static final void main();
    Code:
       0: new           #8                  // class oct_challenge2021/Trie
       3: dup
       4: invokespecial #11                 // Method oct_challenge2021/Trie."<init>":()V
       7: astore_0
       8: aload_0
       9: ldc           #13                 // String apple
      11: invokevirtual #17                 // Method oct_challenge2021/Trie.insert:(Ljava/lang/String;)V
      14: aload_0
      15: ldc           #13                 // String apple
      17: invokevirtual #21                 // Method oct_challenge2021/Trie.search:(Ljava/lang/String;)Z
      20: istore_1
      21: getstatic     #27                 // Field kotlin/_Assertions.ENABLED:Z
      24: ifeq          43
      27: iload_1
      28: ifne          43
      31: ldc           #29                 // String Assertion failed
      33: astore_2
      34: new           #31                 // class java/lang/AssertionError
      37: dup
      38: aload_2
      39: invokespecial #34                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
      42: athrow
      43: aload_0
      44: ldc           #36                 // String app
      46: invokevirtual #21                 // Method oct_challenge2021/Trie.search:(Ljava/lang/String;)Z
      49: istore_2
      50: iload_2
      51: ifne          58
      54: iconst_1
      55: goto          59
      58: iconst_0
      59: istore_3
      60: getstatic     #27                 // Field kotlin/_Assertions.ENABLED:Z
      63: ifeq          84
      66: iload_3
      67: ifne          84
      70: ldc           #29                 // String Assertion failed
      72: astore        4
      74: new           #31                 // class java/lang/AssertionError
      77: dup
      78: aload         4
      80: invokespecial #34                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
      83: athrow
      84: aload_0
      85: ldc           #36                 // String app
      87: invokevirtual #39                 // Method oct_challenge2021/Trie.startsWith:(Ljava/lang/String;)Z
      90: istore_3
      91: getstatic     #27                 // Field kotlin/_Assertions.ENABLED:Z
      94: ifeq          115
      97: iload_3
      98: ifne          115
     101: ldc           #29                 // String Assertion failed
     103: astore        4
     105: new           #31                 // class java/lang/AssertionError
     108: dup
     109: aload         4
     111: invokespecial #34                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     114: athrow
     115: aload_0
     116: ldc           #36                 // String app
     118: invokevirtual #17                 // Method oct_challenge2021/Trie.insert:(Ljava/lang/String;)V
     121: aload_0
     122: ldc           #36                 // String app
     124: invokevirtual #21                 // Method oct_challenge2021/Trie.search:(Ljava/lang/String;)Z
     127: istore        4
     129: getstatic     #27                 // Field kotlin/_Assertions.ENABLED:Z
     132: ifeq          154
     135: iload         4
     137: ifne          154
     140: ldc           #29                 // String Assertion failed
     142: astore        5
     144: new           #31                 // class java/lang/AssertionError
     147: dup
     148: aload         5
     150: invokespecial #34                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     153: athrow
     154: return

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


package oct_challenge2021

fun main() {
    assert(longestCommonSubsequence("abcde", "ace") == 3)
    assert(longestCommonSubsequence("abc", "def") == 0)
    assert(longestCommonSubsequence("abc", "abc") == 2)
    val res = longestCommonSubsequence("abc", "abc")
    println(res)
}

fun longestCommonSubsequence(text1: String, text2: String): Int {
    val memo: Array<Array<Int>> = Array(text1.length) {Array(text2.length) {-1} }
    return getMax(text1, text2, 0, 0, memo)
}

private fun getMax(text1: String, text2: String, index1: Int, index2: Int, memo: Array<Array<Int>>): Int {
    if (index1 == text1.length || index2 == text2.length) return 0
    if (memo[index1][index2] != -1) return memo[index1][index2]

    val char1: Char = text1[index1]
    val char2: Char = text2[index2]

    val result = when (char1) {
        char2 -> {
            getMax(text1, text2, index1 + 1, index2 + 1, memo) + 1
        }
        else -> {
            val res1 = getMax(text1, text2, index1, index2 + 1, memo)
            val res2 = getMax(text1, text2, index1 + 1, index2, memo)
            maxOf(res1, res2)
        }
    }
    memo[index1][index2] = result
    return result
}

Compiled from "LongestCommonSubsequence.kt"
public final class oct_challenge2021.LongestCommonSubsequenceKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String abcde
       2: ldc           #10                 // String ace
       4: invokestatic  #14                 // Method longestCommonSubsequence:(Ljava/lang/String;Ljava/lang/String;)I
       7: iconst_3
       8: if_icmpne     15
      11: iconst_1
      12: goto          16
      15: iconst_0
      16: istore_0
      17: getstatic     #20                 // Field kotlin/_Assertions.ENABLED:Z
      20: ifeq          39
      23: iload_0
      24: ifne          39
      27: ldc           #22                 // String Assertion failed
      29: astore_1
      30: new           #24                 // class java/lang/AssertionError
      33: dup
      34: aload_1
      35: invokespecial #28                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
      38: athrow
      39: ldc           #30                 // String abc
      41: ldc           #32                 // String def
      43: invokestatic  #14                 // Method longestCommonSubsequence:(Ljava/lang/String;Ljava/lang/String;)I
      46: ifne          53
      49: iconst_1
      50: goto          54
      53: iconst_0
      54: istore_0
      55: getstatic     #20                 // Field kotlin/_Assertions.ENABLED:Z
      58: ifeq          77
      61: iload_0
      62: ifne          77
      65: ldc           #22                 // String Assertion failed
      67: astore_1
      68: new           #24                 // class java/lang/AssertionError
      71: dup
      72: aload_1
      73: invokespecial #28                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
      76: athrow
      77: ldc           #30                 // String abc
      79: ldc           #30                 // String abc
      81: invokestatic  #14                 // Method longestCommonSubsequence:(Ljava/lang/String;Ljava/lang/String;)I
      84: iconst_2
      85: if_icmpne     92
      88: iconst_1
      89: goto          93
      92: iconst_0
      93: istore_0
      94: getstatic     #20                 // Field kotlin/_Assertions.ENABLED:Z
      97: ifeq          116
     100: iload_0
     101: ifne          116
     104: ldc           #22                 // String Assertion failed
     106: astore_1
     107: new           #24                 // class java/lang/AssertionError
     110: dup
     111: aload_1
     112: invokespecial #28                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     115: athrow
     116: ldc           #30                 // String abc
     118: ldc           #30                 // String abc
     120: invokestatic  #14                 // Method longestCommonSubsequence:(Ljava/lang/String;Ljava/lang/String;)I
     123: istore_0
     124: getstatic     #38                 // Field java/lang/System.out:Ljava/io/PrintStream;
     127: iload_0
     128: invokevirtual #44                 // Method java/io/PrintStream.println:(I)V
     131: return

  public static final int longestCommonSubsequence(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #49                 // String text1
       3: invokestatic  #55                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #57                 // String text2
       9: invokestatic  #55                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_3
      14: aload_0
      15: invokevirtual #63                 // Method java/lang/String.length:()I
      18: istore        4
      20: iload         4
      22: anewarray     #65                 // class "[Ljava/lang/Integer;"
      25: astore        5
      27: iload_3
      28: iload         4
      30: if_icmpge     99
      33: iload_3
      34: istore        6
      36: aload         5
      38: iload         6
      40: iconst_0
      41: istore        7
      43: aload_1
      44: invokevirtual #63                 // Method java/lang/String.length:()I
      47: istore        8
      49: iload         8
      51: anewarray     #67                 // class java/lang/Integer
      54: astore        9
      56: istore        12
      58: astore        11
      60: iload         7
      62: iload         8
      64: if_icmpge     86
      67: iload         7
      69: istore        10
      71: aload         9
      73: iload         10
      75: iconst_m1
      76: invokestatic  #71                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: aastore
      80: iinc          7, 1
      83: goto          60
      86: aload         11
      88: iload         12
      90: aload         9
      92: aastore
      93: iinc          3, 1
      96: goto          27
      99: aload         5
     101: astore_2
     102: aload_0
     103: aload_1
     104: iconst_0
     105: iconst_0
     106: aload_2
     107: invokestatic  #75                 // Method getMax:(Ljava/lang/String;Ljava/lang/String;II[[Ljava/lang/Integer;)I
     110: ireturn

  private static final int getMax(java.lang.String, java.lang.String, int, int, java.lang.Integer[][]);
    Code:
       0: iload_2
       1: aload_0
       2: invokevirtual #63                 // Method java/lang/String.length:()I
       5: if_icmpeq     16
       8: iload_3
       9: aload_1
      10: invokevirtual #63                 // Method java/lang/String.length:()I
      13: if_icmpne     18
      16: iconst_0
      17: ireturn
      18: aload         4
      20: iload_2
      21: aaload
      22: iload_3
      23: aaload
      24: invokevirtual #82                 // Method java/lang/Integer.intValue:()I
      27: iconst_m1
      28: if_icmpeq     41
      31: aload         4
      33: iload_2
      34: aaload
      35: iload_3
      36: aaload
      37: invokevirtual #82                 // Method java/lang/Integer.intValue:()I
      40: ireturn
      41: aload_0
      42: iload_2
      43: invokevirtual #86                 // Method java/lang/String.charAt:(I)C
      46: istore        5
      48: aload_1
      49: iload_3
      50: invokevirtual #86                 // Method java/lang/String.charAt:(I)C
      53: istore        6
      55: iload         5
      57: iload         6
      59: if_icmpne     80
      62: aload_0
      63: aload_1
      64: iload_2
      65: iconst_1
      66: iadd
      67: iload_3
      68: iconst_1
      69: iadd
      70: aload         4
      72: invokestatic  #75                 // Method getMax:(Ljava/lang/String;Ljava/lang/String;II[[Ljava/lang/Integer;)I
      75: iconst_1
      76: iadd
      77: goto          113
      80: aload_0
      81: aload_1
      82: iload_2
      83: iload_3
      84: iconst_1
      85: iadd
      86: aload         4
      88: invokestatic  #75                 // Method getMax:(Ljava/lang/String;Ljava/lang/String;II[[Ljava/lang/Integer;)I
      91: istore        8
      93: aload_0
      94: aload_1
      95: iload_2
      96: iconst_1
      97: iadd
      98: iload_3
      99: aload         4
     101: invokestatic  #75                 // Method getMax:(Ljava/lang/String;Ljava/lang/String;II[[Ljava/lang/Integer;)I
     104: istore        9
     106: iload         8
     108: iload         9
     110: invokestatic  #92                 // Method java/lang/Math.max:(II)I
     113: istore        7
     115: aload         4
     117: iload_2
     118: aaload
     119: iload_3
     120: iload         7
     122: invokestatic  #71                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     125: aastore
     126: iload         7
     128: ireturn

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


package oct_challenge2021

fun main() {
    val grid = arrayOf(
        intArrayOf(0, 1, 0, 0),
        intArrayOf(1, 1, 1, 0),
        intArrayOf(0, 1, 0, 0),
        intArrayOf(1, 1, 0, 0),
    )
    val result = Solution().islandPerimeter(grid)
    assert(result == 16)
    println(result)
}

class Solution {
    private lateinit var grid: Array<IntArray>
    private lateinit var visited: Array<IntArray>
    private val dirs = arrayOf(intArrayOf(1, 0), intArrayOf(-1, 0), intArrayOf(0, 1), intArrayOf(0, -1))
    private var result: Int = 0

    fun islandPerimeter(grid: Array<IntArray>): Int {
        this.grid = grid
        this.visited = Array(grid.size) { IntArray(grid[0].size) { 0 } }
        for (i in grid.indices) {
            for (j in grid[0].indices) {
                if (grid[i][j] == 1 && visited[i][j] == 0) {
                    traverse(i, j)
                    return result
                }
            }
        }
        return result
    }

    private fun traverse(i: Int, j: Int) {
        val m = grid.size
        val n = grid[0].size
        visited[i][j] = 1
        for (dir in dirs) {
            val newI = i + dir[0]
            val newJ = j + dir[1]
            val canTraverse = newI in 0 until m && newJ in 0 until n && grid[newI][newJ] == 1
            when {
                canTraverse -> {
                    if (visited[newI][newJ] == 0) traverse(newI, newJ)
                }
                else -> {
                    result++
                }
            }
        }
    }

}

Compiled from "IslandPerimeter.kt"
public final class oct_challenge2021.IslandPerimeterKt {
  public static final void main();
    Code:
       0: iconst_4
       1: anewarray     #8                  // class "[I"
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iconst_4
       8: newarray       int
      10: astore_2
      11: aload_2
      12: iconst_0
      13: iconst_0
      14: iastore
      15: aload_2
      16: iconst_1
      17: iconst_1
      18: iastore
      19: aload_2
      20: iconst_2
      21: iconst_0
      22: iastore
      23: aload_2
      24: iconst_3
      25: iconst_0
      26: iastore
      27: aload_2
      28: aastore
      29: aload_1
      30: iconst_1
      31: iconst_4
      32: newarray       int
      34: astore_2
      35: aload_2
      36: iconst_0
      37: iconst_1
      38: iastore
      39: aload_2
      40: iconst_1
      41: iconst_1
      42: iastore
      43: aload_2
      44: iconst_2
      45: iconst_1
      46: iastore
      47: aload_2
      48: iconst_3
      49: iconst_0
      50: iastore
      51: aload_2
      52: aastore
      53: aload_1
      54: iconst_2
      55: iconst_4
      56: newarray       int
      58: astore_2
      59: aload_2
      60: iconst_0
      61: iconst_0
      62: iastore
      63: aload_2
      64: iconst_1
      65: iconst_1
      66: iastore
      67: aload_2
      68: iconst_2
      69: iconst_0
      70: iastore
      71: aload_2
      72: iconst_3
      73: iconst_0
      74: iastore
      75: aload_2
      76: aastore
      77: aload_1
      78: iconst_3
      79: iconst_4
      80: newarray       int
      82: astore_2
      83: aload_2
      84: iconst_0
      85: iconst_1
      86: iastore
      87: aload_2
      88: iconst_1
      89: iconst_1
      90: iastore
      91: aload_2
      92: iconst_2
      93: iconst_0
      94: iastore
      95: aload_2
      96: iconst_3
      97: iconst_0
      98: iastore
      99: aload_2
     100: aastore
     101: aload_1
     102: astore_0
     103: new           #10                 // class oct_challenge2021/Solution
     106: dup
     107: invokespecial #13                 // Method oct_challenge2021/Solution."<init>":()V
     110: aload_0
     111: invokevirtual #17                 // Method oct_challenge2021/Solution.islandPerimeter:([[I)I
     114: istore_1
     115: iload_1
     116: bipush        16
     118: if_icmpne     125
     121: iconst_1
     122: goto          126
     125: iconst_0
     126: istore_2
     127: getstatic     #23                 // Field kotlin/_Assertions.ENABLED:Z
     130: ifeq          149
     133: iload_2
     134: ifne          149
     137: ldc           #25                 // String Assertion failed
     139: astore_3
     140: new           #27                 // class java/lang/AssertionError
     143: dup
     144: aload_3
     145: invokespecial #30                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
     148: athrow
     149: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
     152: iload_1
     153: invokevirtual #42                 // Method java/io/PrintStream.println:(I)V
     156: return

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


package bk70

import java.util.*

// [[0,2,0]]
// [2,2]
// [0,1]
// 1
fun main() {
    val res = Problem3().highestRankedKItems(
        arrayOf(
            intArrayOf(0, 2, 0),
        ),
        intArrayOf(2, 2),
        intArrayOf(0, 1),
        1
    )
    println(res)
}

class Problem3 {
    private lateinit var grid: Array<IntArray>
    private lateinit var pricing: IntArray
    private var visitedPoints = mutableListOf<Point>()

    fun highestRankedKItems(grid: Array<IntArray>, pricing: IntArray, start: IntArray, k: Int): List<List<Int>> {
        this.grid = grid
        this.pricing = pricing
        bfs(start[0], start[1])
        return visitedPoints
            .filter {
                it.`val` != 1 && it.`val` >= pricing[0] && it.`val` <= pricing[1]
            }
            .sortedWith(
                compareBy<Point> { it.dist }
                    .thenBy {
                        it.`val`
                    }
                    .thenBy { it.x }
                    .thenBy { it.y }
            )
            .map {
                listOf(it.x, it.y)
            }
            .take(k)
    }

    private fun bfs(i: Int, j: Int) {
        val queue: Queue<Point> =
            LinkedList<Point>()
        val visited = Array(grid.size) {
            BooleanArray(
                grid[0].size
            )
        }

        val directions = arrayOf(intArrayOf(1, 0), intArrayOf(0, 1), intArrayOf(-1, 0), intArrayOf(0, -1))

        val first = Point(i, j, 0, grid[i][j])
        queue.add(first)
        visitedPoints.add(first)
        visited[first.x][first.y] = true

        var distance = 0
        while (!queue.isEmpty()) {
            distance++
            val size = queue.size
            for (i in 0 until size) {
                val curr: Point = queue.poll()
                for (direction in directions) {
                    val newPoint =
                        Point(
                            curr.x + direction[0],
                            curr.y + direction[1],
                            distance,
                            0
                        )
                    if (newPoint.x >= 0 && newPoint.x < grid.size && newPoint.y >= 0 && newPoint.y < grid[0].size &&
                        !visited[newPoint.x][newPoint.y] && grid[newPoint.x][newPoint.y] != 0
                    ) {
                        newPoint.`val` = grid[newPoint.x][newPoint.y]
                        visited[newPoint.x][newPoint.y] = true
                        queue.add(newPoint)
                        visitedPoints.add(newPoint)
                    }
                }
            }
        }
    }

    internal class Point(var x: Int, var y: Int, var dist: Int, var `val`: Int)
}

Compiled from "Comparisons.kt"
public final class bk70.Problem3$highestRankedKItems$$inlined$thenBy$3<T> implements java.util.Comparator {
  final java.util.Comparator $this_thenBy;

  public bk70.Problem3$highestRankedKItems$$inlined$thenBy$3(java.util.Comparator);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_thenBy:Ljava/util/Comparator;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public final int compare(T, T);
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_thenBy:Ljava/util/Comparator;
       4: aload_1
       5: aload_2
       6: invokeinterface #29,  3           // InterfaceMethod java/util/Comparator.compare:(Ljava/lang/Object;Ljava/lang/Object;)I
      11: istore_3
      12: iload_3
      13: ifeq          20
      16: iload_3
      17: goto          68
      20: aload_1
      21: checkcast     #31                 // class bk70/Problem3$Point
      24: astore        4
      26: iconst_0
      27: istore        5
      29: aload         4
      31: invokevirtual #35                 // Method bk70/Problem3$Point.getY:()I
      34: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: checkcast     #43                 // class java/lang/Comparable
      40: aload_2
      41: checkcast     #31                 // class bk70/Problem3$Point
      44: astore        4
      46: astore        6
      48: iconst_0
      49: istore        5
      51: aload         4
      53: invokevirtual #35                 // Method bk70/Problem3$Point.getY:()I
      56: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: checkcast     #43                 // class java/lang/Comparable
      62: aload         6
      64: swap
      65: invokestatic  #49                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      68: ireturn
}

Compiled from "Comparisons.kt"
public final class bk70.Problem3$highestRankedKItems$$inlined$thenBy$1<T> implements java.util.Comparator {
  final java.util.Comparator $this_thenBy;

  public bk70.Problem3$highestRankedKItems$$inlined$thenBy$1(java.util.Comparator);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_thenBy:Ljava/util/Comparator;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public final int compare(T, T);
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_thenBy:Ljava/util/Comparator;
       4: aload_1
       5: aload_2
       6: invokeinterface #29,  3           // InterfaceMethod java/util/Comparator.compare:(Ljava/lang/Object;Ljava/lang/Object;)I
      11: istore_3
      12: iload_3
      13: ifeq          20
      16: iload_3
      17: goto          68
      20: aload_1
      21: checkcast     #31                 // class bk70/Problem3$Point
      24: astore        4
      26: iconst_0
      27: istore        5
      29: aload         4
      31: invokevirtual #35                 // Method bk70/Problem3$Point.getVal:()I
      34: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: checkcast     #43                 // class java/lang/Comparable
      40: aload_2
      41: checkcast     #31                 // class bk70/Problem3$Point
      44: astore        4
      46: astore        6
      48: iconst_0
      49: istore        5
      51: aload         4
      53: invokevirtual #35                 // Method bk70/Problem3$Point.getVal:()I
      56: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: checkcast     #43                 // class java/lang/Comparable
      62: aload         6
      64: swap
      65: invokestatic  #49                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      68: ireturn
}

Compiled from "Comparisons.kt"
public final class bk70.Problem3$highestRankedKItems$$inlined$thenBy$2<T> implements java.util.Comparator {
  final java.util.Comparator $this_thenBy;

  public bk70.Problem3$highestRankedKItems$$inlined$thenBy$2(java.util.Comparator);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_thenBy:Ljava/util/Comparator;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public final int compare(T, T);
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_thenBy:Ljava/util/Comparator;
       4: aload_1
       5: aload_2
       6: invokeinterface #29,  3           // InterfaceMethod java/util/Comparator.compare:(Ljava/lang/Object;Ljava/lang/Object;)I
      11: istore_3
      12: iload_3
      13: ifeq          20
      16: iload_3
      17: goto          68
      20: aload_1
      21: checkcast     #31                 // class bk70/Problem3$Point
      24: astore        4
      26: iconst_0
      27: istore        5
      29: aload         4
      31: invokevirtual #35                 // Method bk70/Problem3$Point.getX:()I
      34: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: checkcast     #43                 // class java/lang/Comparable
      40: aload_2
      41: checkcast     #31                 // class bk70/Problem3$Point
      44: astore        4
      46: astore        6
      48: iconst_0
      49: istore        5
      51: aload         4
      53: invokevirtual #35                 // Method bk70/Problem3$Point.getX:()I
      56: invokestatic  #41                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: checkcast     #43                 // class java/lang/Comparable
      62: aload         6
      64: swap
      65: invokestatic  #49                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      68: ireturn
}

Compiled from "Problem3.kt"
public final class bk70.Problem3$Point {
  private int x;

  private int y;

  private int dist;

  private int val;

  public bk70.Problem3$Point(int, int, 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: aload_0
      15: iload_3
      16: putfield      #19                 // Field dist:I
      19: aload_0
      20: iload         4
      22: putfield      #22                 // Field val:I
      25: return

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

  public final void setX(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #13                 // Field x:I
       5: return

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

  public final void setY(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #16                 // Field y:I
       5: return

  public final int getDist();
    Code:
       0: aload_0
       1: getfield      #19                 // Field dist:I
       4: ireturn

  public final void setDist(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #19                 // Field dist:I
       5: return

  public final int getVal();
    Code:
       0: aload_0
       1: getfield      #22                 // Field val:I
       4: ireturn

  public final void setVal(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #22                 // Field val:I
       5: return
}

Compiled from "Comparisons.kt"
public final class bk70.Problem3$highestRankedKItems$$inlined$compareBy$1<T> implements java.util.Comparator {
  public bk70.Problem3$highestRankedKItems$$inlined$compareBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class bk70/Problem3$Point
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method bk70/Problem3$Point.getDist:()I
      12: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class bk70/Problem3$Point
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method bk70/Problem3$Point.getDist:()I
      32: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: checkcast     #35                 // class java/lang/Comparable
      38: aload         5
      40: swap
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}

Compiled from "Problem3.kt"
public final class bk70.Problem3Kt {
  public static final void main();
    Code:
       0: new           #8                  // class bk70/Problem3
       3: dup
       4: invokespecial #11                 // Method bk70/Problem3."<init>":()V
       7: iconst_1
       8: anewarray     #13                 // class "[I"
      11: astore_1
      12: aload_1
      13: iconst_0
      14: iconst_3
      15: newarray       int
      17: astore_2
      18: aload_2
      19: iconst_0
      20: iconst_0
      21: iastore
      22: aload_2
      23: iconst_1
      24: iconst_2
      25: iastore
      26: aload_2
      27: iconst_2
      28: iconst_0
      29: iastore
      30: aload_2
      31: aastore
      32: aload_1
      33: iconst_2
      34: newarray       int
      36: astore_1
      37: aload_1
      38: iconst_0
      39: iconst_2
      40: iastore
      41: aload_1
      42: iconst_1
      43: iconst_2
      44: iastore
      45: aload_1
      46: iconst_2
      47: newarray       int
      49: astore_1
      50: aload_1
      51: iconst_0
      52: iconst_0
      53: iastore
      54: aload_1
      55: iconst_1
      56: iconst_1
      57: iastore
      58: aload_1
      59: iconst_1
      60: invokevirtual #17                 // Method bk70/Problem3.highestRankedKItems:([[I[I[II)Ljava/util/List;
      63: astore_0
      64: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
      67: aload_0
      68: invokevirtual #29                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      71: return

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

Compiled from "Problem3.kt"
public final class bk70.Problem3 {
  private int[][] grid;

  private int[] pricing;

  private java.util.List<bk70.Problem3$Point> visitedPoints;

  public bk70.Problem3();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: new           #10                 // class java/util/ArrayList
       8: dup
       9: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      12: checkcast     #13                 // class java/util/List
      15: putfield      #17                 // Field visitedPoints:Ljava/util/List;
      18: return

  public final java.util.List<java.util.List<java.lang.Integer>> highestRankedKItems(int[][], int[], int[], int);
    Code:
       0: aload_1
       1: ldc           #25                 // String grid
       3: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #33                 // String pricing
       9: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #35                 // String start
      15: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload_0
      19: aload_1
      20: putfield      #38                 // Field grid:[[I
      23: aload_0
      24: aload_2
      25: putfield      #41                 // Field pricing:[I
      28: aload_0
      29: aload_3
      30: iconst_0
      31: iaload
      32: aload_3
      33: iconst_1
      34: iaload
      35: invokespecial #45                 // Method bfs:(II)V
      38: aload_0
      39: getfield      #17                 // Field visitedPoints:Ljava/util/List;
      42: checkcast     #47                 // class java/lang/Iterable
      45: astore        5
      47: nop
      48: iconst_0
      49: istore        6
      51: aload         5
      53: astore        7
      55: new           #10                 // class java/util/ArrayList
      58: dup
      59: invokespecial #11                 // Method java/util/ArrayList."<init>":()V
      62: checkcast     #49                 // class java/util/Collection
      65: astore        8
      67: iconst_0
      68: istore        9
      70: aload         7
      72: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      77: astore        10
      79: aload         10
      81: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      86: ifeq          160
      89: aload         10
      91: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      96: astore        11
      98: aload         11
     100: checkcast     #65                 // class bk70/Problem3$Point
     103: astore        12
     105: iconst_0
     106: istore        13
     108: aload         12
     110: invokevirtual #69                 // Method bk70/Problem3$Point.getVal:()I
     113: iconst_1
     114: if_icmpeq     143
     117: aload         12
     119: invokevirtual #69                 // Method bk70/Problem3$Point.getVal:()I
     122: aload_2
     123: iconst_0
     124: iaload
     125: if_icmplt     143
     128: aload         12
     130: invokevirtual #69                 // Method bk70/Problem3$Point.getVal:()I
     133: aload_2
     134: iconst_1
     135: iaload
     136: if_icmpgt     143
     139: iconst_1
     140: goto          144
     143: iconst_0
     144: ifeq          79
     147: aload         8
     149: aload         11
     151: invokeinterface #73,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          79
     160: aload         8
     162: checkcast     #13                 // class java/util/List
     165: nop
     166: checkcast     #47                 // class java/lang/Iterable
     169: new           #75                 // class bk70/Problem3$highestRankedKItems$$inlined$compareBy$1
     172: dup
     173: invokespecial #76                 // Method bk70/Problem3$highestRankedKItems$$inlined$compareBy$1."<init>":()V
     176: checkcast     #78                 // class java/util/Comparator
     179: astore        5
     181: new           #80                 // class bk70/Problem3$highestRankedKItems$$inlined$thenBy$1
     184: dup
     185: aload         5
     187: invokespecial #83                 // Method bk70/Problem3$highestRankedKItems$$inlined$thenBy$1."<init>":(Ljava/util/Comparator;)V
     190: checkcast     #78                 // class java/util/Comparator
     193: astore        5
     195: new           #85                 // class bk70/Problem3$highestRankedKItems$$inlined$thenBy$2
     198: dup
     199: aload         5
     201: invokespecial #86                 // Method bk70/Problem3$highestRankedKItems$$inlined$thenBy$2."<init>":(Ljava/util/Comparator;)V
     204: checkcast     #78                 // class java/util/Comparator
     207: astore        5
     209: new           #88                 // class bk70/Problem3$highestRankedKItems$$inlined$thenBy$3
     212: dup
     213: aload         5
     215: invokespecial #89                 // Method bk70/Problem3$highestRankedKItems$$inlined$thenBy$3."<init>":(Ljava/util/Comparator;)V
     218: checkcast     #78                 // class java/util/Comparator
     221: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     224: checkcast     #47                 // class java/lang/Iterable
     227: astore        5
     229: nop
     230: iconst_0
     231: istore        6
     233: aload         5
     235: astore        7
     237: new           #10                 // class java/util/ArrayList
     240: dup
     241: aload         5
     243: bipush        10
     245: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     248: invokespecial #102                // Method java/util/ArrayList."<init>":(I)V
     251: checkcast     #49                 // class java/util/Collection
     254: astore        8
     256: iconst_0
     257: istore        9
     259: aload         7
     261: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     266: astore        10
     268: aload         10
     270: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     275: ifeq          348
     278: aload         10
     280: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     285: astore        11
     287: aload         8
     289: aload         11
     291: checkcast     #65                 // class bk70/Problem3$Point
     294: astore        12
     296: astore        15
     298: iconst_0
     299: istore        13
     301: iconst_2
     302: anewarray     #104                // class java/lang/Integer
     305: astore        14
     307: aload         14
     309: iconst_0
     310: aload         12
     312: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     315: invokestatic  #111                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     318: aastore
     319: aload         14
     321: iconst_1
     322: aload         12
     324: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     327: invokestatic  #111                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     330: aastore
     331: aload         14
     333: invokestatic  #118                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     336: aload         15
     338: swap
     339: invokeinterface #73,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     344: pop
     345: goto          268
     348: aload         8
     350: checkcast     #13                 // class java/util/List
     353: nop
     354: checkcast     #47                 // class java/lang/Iterable
     357: iload         4
     359: invokestatic  #122                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     362: areturn

  private final void bfs(int, int);
    Code:
       0: new           #146                // class java/util/LinkedList
       3: dup
       4: invokespecial #147                // Method java/util/LinkedList."<init>":()V
       7: checkcast     #149                // class java/util/Queue
      10: astore_3
      11: iconst_0
      12: istore        5
      14: aload_0
      15: getfield      #38                 // Field grid:[[I
      18: dup
      19: ifnonnull     29
      22: pop
      23: ldc           #25                 // String grid
      25: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
      28: aconst_null
      29: checkcast     #155                // class "[Ljava/lang/Object;"
      32: arraylength
      33: istore        6
      35: iload         6
      37: anewarray     #157                // class "[Z"
      40: astore        7
      42: iload         5
      44: iload         6
      46: if_icmpge     84
      49: iload         5
      51: istore        8
      53: aload         7
      55: iload         8
      57: aload_0
      58: getfield      #38                 // Field grid:[[I
      61: dup
      62: ifnonnull     72
      65: pop
      66: ldc           #25                 // String grid
      68: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
      71: aconst_null
      72: iconst_0
      73: aaload
      74: arraylength
      75: newarray       boolean
      77: aastore
      78: iinc          5, 1
      81: goto          42
      84: aload         7
      86: astore        4
      88: iconst_4
      89: anewarray     #144                // class "[I"
      92: astore        6
      94: aload         6
      96: iconst_0
      97: iconst_2
      98: newarray       int
     100: astore        7
     102: aload         7
     104: iconst_0
     105: iconst_1
     106: iastore
     107: aload         7
     109: iconst_1
     110: iconst_0
     111: iastore
     112: aload         7
     114: aastore
     115: aload         6
     117: iconst_1
     118: iconst_2
     119: newarray       int
     121: astore        7
     123: aload         7
     125: iconst_0
     126: iconst_0
     127: iastore
     128: aload         7
     130: iconst_1
     131: iconst_1
     132: iastore
     133: aload         7
     135: aastore
     136: aload         6
     138: iconst_2
     139: iconst_2
     140: newarray       int
     142: astore        7
     144: aload         7
     146: iconst_0
     147: iconst_m1
     148: iastore
     149: aload         7
     151: iconst_1
     152: iconst_0
     153: iastore
     154: aload         7
     156: aastore
     157: aload         6
     159: iconst_3
     160: iconst_2
     161: newarray       int
     163: astore        7
     165: aload         7
     167: iconst_0
     168: iconst_0
     169: iastore
     170: aload         7
     172: iconst_1
     173: iconst_m1
     174: iastore
     175: aload         7
     177: aastore
     178: aload         6
     180: astore        5
     182: new           #65                 // class bk70/Problem3$Point
     185: dup
     186: iload_1
     187: iload_2
     188: iconst_0
     189: aload_0
     190: getfield      #38                 // Field grid:[[I
     193: dup
     194: ifnonnull     204
     197: pop
     198: ldc           #25                 // String grid
     200: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
     203: aconst_null
     204: iload_1
     205: aaload
     206: iload_2
     207: iaload
     208: invokespecial #160                // Method bk70/Problem3$Point."<init>":(IIII)V
     211: astore        6
     213: aload_3
     214: aload         6
     216: invokeinterface #161,  2          // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
     221: pop
     222: aload_0
     223: getfield      #17                 // Field visitedPoints:Ljava/util/List;
     226: aload         6
     228: invokeinterface #162,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     233: pop
     234: aload         4
     236: aload         6
     238: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     241: aaload
     242: aload         6
     244: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     247: iconst_1
     248: bastore
     249: iconst_0
     250: istore        7
     252: aload_3
     253: invokeinterface #165,  1          // InterfaceMethod java/util/Queue.isEmpty:()Z
     258: ifne          552
     261: iinc          7, 1
     264: aload_3
     265: invokeinterface #168,  1          // InterfaceMethod java/util/Queue.size:()I
     270: istore        8
     272: iconst_0
     273: istore        9
     275: iload         9
     277: iload         8
     279: if_icmpge     252
     282: aload_3
     283: invokeinterface #171,  1          // InterfaceMethod java/util/Queue.poll:()Ljava/lang/Object;
     288: dup
     289: ldc           #173                // String poll(...)
     291: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     294: checkcast     #65                 // class bk70/Problem3$Point
     297: astore        10
     299: iconst_0
     300: istore        11
     302: aload         5
     304: checkcast     #155                // class "[Ljava/lang/Object;"
     307: arraylength
     308: istore        12
     310: iload         11
     312: iload         12
     314: if_icmpge     546
     317: aload         5
     319: iload         11
     321: aaload
     322: astore        13
     324: new           #65                 // class bk70/Problem3$Point
     327: dup
     328: aload         10
     330: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     333: aload         13
     335: iconst_0
     336: iaload
     337: iadd
     338: aload         10
     340: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     343: aload         13
     345: iconst_1
     346: iaload
     347: iadd
     348: iload         7
     350: iconst_0
     351: invokespecial #160                // Method bk70/Problem3$Point."<init>":(IIII)V
     354: astore        14
     356: aload         14
     358: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     361: iflt          540
     364: aload         14
     366: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     369: aload_0
     370: getfield      #38                 // Field grid:[[I
     373: dup
     374: ifnonnull     384
     377: pop
     378: ldc           #25                 // String grid
     380: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
     383: aconst_null
     384: checkcast     #155                // class "[Ljava/lang/Object;"
     387: arraylength
     388: if_icmpge     540
     391: aload         14
     393: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     396: iflt          540
     399: aload         14
     401: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     404: aload_0
     405: getfield      #38                 // Field grid:[[I
     408: dup
     409: ifnonnull     419
     412: pop
     413: ldc           #25                 // String grid
     415: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
     418: aconst_null
     419: iconst_0
     420: aaload
     421: arraylength
     422: if_icmpge     540
     425: aload         4
     427: aload         14
     429: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     432: aaload
     433: aload         14
     435: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     438: baload
     439: ifne          540
     442: aload_0
     443: getfield      #38                 // Field grid:[[I
     446: dup
     447: ifnonnull     457
     450: pop
     451: ldc           #25                 // String grid
     453: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
     456: aconst_null
     457: aload         14
     459: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     462: aaload
     463: aload         14
     465: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     468: iaload
     469: ifeq          540
     472: aload         14
     474: aload_0
     475: getfield      #38                 // Field grid:[[I
     478: dup
     479: ifnonnull     489
     482: pop
     483: ldc           #25                 // String grid
     485: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
     488: aconst_null
     489: aload         14
     491: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     494: aaload
     495: aload         14
     497: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     500: iaload
     501: invokevirtual #179                // Method bk70/Problem3$Point.setVal:(I)V
     504: aload         4
     506: aload         14
     508: invokevirtual #107                // Method bk70/Problem3$Point.getX:()I
     511: aaload
     512: aload         14
     514: invokevirtual #114                // Method bk70/Problem3$Point.getY:()I
     517: iconst_1
     518: bastore
     519: aload_3
     520: aload         14
     522: invokeinterface #161,  2          // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
     527: pop
     528: aload_0
     529: getfield      #17                 // Field visitedPoints:Ljava/util/List;
     532: aload         14
     534: invokeinterface #162,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     539: pop
     540: iinc          11, 1
     543: goto          310
     546: iinc          9, 1
     549: goto          275
     552: return
}


package wk271

fun main() {
//    val res = Problem3().minimumRefill(intArrayOf(2,2,3,3), 5 ,5)
//    val res = Problem3().minimumRefill(intArrayOf(2,2,3,3), 3 ,4)
    val res = Problem3().minimumRefill(intArrayOf(2, 2, 5, 2, 2), 5, 5)
    println(res)
}

class Problem3 {
    fun minimumRefill(plants: IntArray, capacityA: Int, capacityB: Int): Int {
        var aliceCur = 0
        var bobCur = plants.size - 1
        var aliceCurCapacity = capacityA
        var bobCurCapacity = capacityB
        var result = 0
        while (aliceCur <= bobCur) {
            if (aliceCur == bobCur) {
                if (bobCurCapacity > aliceCurCapacity) {
                    if (plants[bobCur] <= bobCurCapacity) {
                        bobCurCapacity -= plants[bobCur]
                    } else {
                        result++
                    }
                } else {
                    if (plants[aliceCur] <= aliceCurCapacity) {
                        aliceCurCapacity -= plants[aliceCur]
                    } else {
                        result++
                    }
                }
                return result
            }
            if (plants[aliceCur] <= aliceCurCapacity) {
                aliceCurCapacity -= plants[aliceCur]
            } else {
                result++
                aliceCurCapacity = capacityA
                aliceCurCapacity -= plants[aliceCur]
            }

            if (plants[bobCur] <= bobCurCapacity) {
                bobCurCapacity -= plants[bobCur]
            } else {
                result++
                bobCurCapacity = capacityB
                bobCurCapacity -= plants[bobCur]
            }

            aliceCur++
            bobCur--
        }
        return result
    }
}

Compiled from "Problem3.kt"
public final class wk271.Problem3Kt {
  public static final void main();
    Code:
       0: new           #8                  // class wk271/Problem3
       3: dup
       4: invokespecial #11                 // Method wk271/Problem3."<init>":()V
       7: iconst_5
       8: newarray       int
      10: astore_1
      11: aload_1
      12: iconst_0
      13: iconst_2
      14: iastore
      15: aload_1
      16: iconst_1
      17: iconst_2
      18: iastore
      19: aload_1
      20: iconst_2
      21: iconst_5
      22: iastore
      23: aload_1
      24: iconst_3
      25: iconst_2
      26: iastore
      27: aload_1
      28: iconst_4
      29: iconst_2
      30: iastore
      31: aload_1
      32: iconst_5
      33: iconst_5
      34: invokevirtual #15                 // Method wk271/Problem3.minimumRefill:([III)I
      37: istore_0
      38: getstatic     #21                 // Field java/lang/System.out:Ljava/io/PrintStream;
      41: iload_0
      42: invokevirtual #27                 // Method java/io/PrintStream.println:(I)V
      45: return

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

Compiled from "Problem3.kt"
public final class wk271.Problem3 {
  public wk271.Problem3();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int minimumRefill(int[], int, int);
    Code:
       0: aload_1
       1: ldc           #15                 // String plants
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore        4
       9: aload_1
      10: arraylength
      11: iconst_1
      12: isub
      13: istore        5
      15: iload_2
      16: istore        6
      18: iload_3
      19: istore        7
      21: iconst_0
      22: istore        8
      24: iload         4
      26: iload         5
      28: if_icmpgt     186
      31: iload         4
      33: iload         5
      35: if_icmpne     105
      38: iload         7
      40: iload         6
      42: if_icmple     75
      45: aload_1
      46: iload         5
      48: iaload
      49: iload         7
      51: if_icmpgt     66
      54: iload         7
      56: aload_1
      57: iload         5
      59: iaload
      60: isub
      61: istore        7
      63: goto          102
      66: iload         8
      68: iinc          8, 1
      71: pop
      72: goto          102
      75: aload_1
      76: iload         4
      78: iaload
      79: iload         6
      81: if_icmpgt     96
      84: iload         6
      86: aload_1
      87: iload         4
      89: iaload
      90: isub
      91: istore        6
      93: goto          102
      96: iload         8
      98: iinc          8, 1
     101: pop
     102: iload         8
     104: ireturn
     105: aload_1
     106: iload         4
     108: iaload
     109: iload         6
     111: if_icmpgt     126
     114: iload         6
     116: aload_1
     117: iload         4
     119: iaload
     120: isub
     121: istore        6
     123: goto          141
     126: iinc          8, 1
     129: iload_2
     130: istore        6
     132: iload         6
     134: aload_1
     135: iload         4
     137: iaload
     138: isub
     139: istore        6
     141: aload_1
     142: iload         5
     144: iaload
     145: iload         7
     147: if_icmpgt     162
     150: iload         7
     152: aload_1
     153: iload         5
     155: iaload
     156: isub
     157: istore        7
     159: goto          177
     162: iinc          8, 1
     165: iload_3
     166: istore        7
     168: iload         7
     170: aload_1
     171: iload         5
     173: iaload
     174: isub
     175: istore        7
     177: iinc          4, 1
     180: iinc          5, -1
     183: goto          24
     186: iload         8
     188: ireturn
}


package bk65

import kotlin.math.abs

fun main() {
    // "aaaa"
    // "bccb"
    val resul = Problem1().checkAlmostEquivalent("aaaa", "bccb")
    println(resul)
}
class Problem1 {
    fun checkAlmostEquivalent(word1: String, word2: String): Boolean {
        val map1 = word1.toCharArray().toList().groupingBy { it }.eachCount()
        val map2 = word2.toCharArray().toList().groupingBy { it }.eachCount()
        val bigger = if (map1.size > map2.size) map1 else map2
        val smaller = if (map1.size <= map2.size) map1 else map2
        for (entry: Map.Entry<Char, Int> in bigger) {
            val char1 = entry.key
            val char1Count = entry.value
            val char2Count = smaller[char1] ?: 0
            if (abs(char1Count - char2Count) > 3) return false
        }
        for (entry: Map.Entry<Char, Int> in smaller) {
            val char1 = entry.key
            val char1Count = entry.value
            val char2Count = bigger[char1] ?: 0
            if (abs(char1Count - char2Count) > 3) return false
        }
        return true
    }
}

Compiled from "_Collections.kt"
public final class bk65.Problem1$checkAlmostEquivalent$$inlined$groupingBy$2 implements kotlin.collections.Grouping<java.lang.Character, java.lang.Character> {
  final java.lang.Iterable $this_groupingBy;

  public bk65.Problem1$checkAlmostEquivalent$$inlined$groupingBy$2(java.lang.Iterable);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_groupingBy:Ljava/lang/Iterable;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public java.util.Iterator<java.lang.Character> sourceIterator();
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_groupingBy:Ljava/lang/Iterable;
       4: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: areturn

  public java.lang.Character keyOf(java.lang.Character);
    Code:
       0: aload_1
       1: checkcast     #37                 // class java/lang/Character
       4: invokevirtual #41                 // Method java/lang/Character.charValue:()C
       7: istore_2
       8: iconst_0
       9: istore_3
      10: iload_2
      11: invokestatic  #45                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      14: areturn
}

Compiled from "_Collections.kt"
public final class bk65.Problem1$checkAlmostEquivalent$$inlined$groupingBy$1 implements kotlin.collections.Grouping<java.lang.Character, java.lang.Character> {
  final java.lang.Iterable $this_groupingBy;

  public bk65.Problem1$checkAlmostEquivalent$$inlined$groupingBy$1(java.lang.Iterable);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $this_groupingBy:Ljava/lang/Iterable;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public java.util.Iterator<java.lang.Character> sourceIterator();
    Code:
       0: aload_0
       1: getfield      #18                 // Field $this_groupingBy:Ljava/lang/Iterable;
       4: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: areturn

  public java.lang.Character keyOf(java.lang.Character);
    Code:
       0: aload_1
       1: checkcast     #37                 // class java/lang/Character
       4: invokevirtual #41                 // Method java/lang/Character.charValue:()C
       7: istore_2
       8: iconst_0
       9: istore_3
      10: iload_2
      11: invokestatic  #45                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      14: areturn
}

Compiled from "Problem1.kt"
public final class bk65.Problem1Kt {
  public static final void main();
    Code:
       0: new           #8                  // class bk65/Problem1
       3: dup
       4: invokespecial #11                 // Method bk65/Problem1."<init>":()V
       7: ldc           #13                 // String aaaa
       9: ldc           #15                 // String bccb
      11: invokevirtual #19                 // Method bk65/Problem1.checkAlmostEquivalent:(Ljava/lang/String;Ljava/lang/String;)Z
      14: istore_0
      15: getstatic     #25                 // Field java/lang/System.out:Ljava/io/PrintStream;
      18: iload_0
      19: invokevirtual #31                 // Method java/io/PrintStream.println:(Z)V
      22: return

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

Compiled from "Problem1.kt"
public final class bk65.Problem1 {
  public bk65.Problem1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final boolean checkAlmostEquivalent(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String word1
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String word2
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: invokevirtual #29                 // Method java/lang/String.toCharArray:()[C
      16: dup
      17: ldc           #31                 // String toCharArray(...)
      19: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      22: invokestatic  #40                 // Method kotlin/collections/ArraysKt.toList:([C)Ljava/util/List;
      25: checkcast     #42                 // class java/lang/Iterable
      28: astore        4
      30: iconst_0
      31: istore        5
      33: new           #44                 // class bk65/Problem1$checkAlmostEquivalent$$inlined$groupingBy$1
      36: dup
      37: aload         4
      39: invokespecial #47                 // Method bk65/Problem1$checkAlmostEquivalent$$inlined$groupingBy$1."<init>":(Ljava/lang/Iterable;)V
      42: checkcast     #49                 // class kotlin/collections/Grouping
      45: invokestatic  #55                 // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
      48: astore_3
      49: aload_2
      50: invokevirtual #29                 // Method java/lang/String.toCharArray:()[C
      53: dup
      54: ldc           #31                 // String toCharArray(...)
      56: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      59: invokestatic  #40                 // Method kotlin/collections/ArraysKt.toList:([C)Ljava/util/List;
      62: checkcast     #42                 // class java/lang/Iterable
      65: astore        5
      67: iconst_0
      68: istore        6
      70: new           #57                 // class bk65/Problem1$checkAlmostEquivalent$$inlined$groupingBy$2
      73: dup
      74: aload         5
      76: invokespecial #58                 // Method bk65/Problem1$checkAlmostEquivalent$$inlined$groupingBy$2."<init>":(Ljava/lang/Iterable;)V
      79: checkcast     #49                 // class kotlin/collections/Grouping
      82: invokestatic  #55                 // Method kotlin/collections/GroupingKt.eachCount:(Lkotlin/collections/Grouping;)Ljava/util/Map;
      85: astore        4
      87: aload_3
      88: invokeinterface #64,  1           // InterfaceMethod java/util/Map.size:()I
      93: aload         4
      95: invokeinterface #64,  1           // InterfaceMethod java/util/Map.size:()I
     100: if_icmple     107
     103: aload_3
     104: goto          109
     107: aload         4
     109: astore        5
     111: aload_3
     112: invokeinterface #64,  1           // InterfaceMethod java/util/Map.size:()I
     117: aload         4
     119: invokeinterface #64,  1           // InterfaceMethod java/util/Map.size:()I
     124: if_icmpgt     131
     127: aload_3
     128: goto          133
     131: aload         4
     133: astore        6
     135: aload         5
     137: invokeinterface #68,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     142: invokeinterface #74,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     147: astore        7
     149: aload         7
     151: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     156: ifeq          244
     159: aload         7
     161: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     166: checkcast     #86                 // class java/util/Map$Entry
     169: astore        8
     171: aload         8
     173: invokeinterface #89,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     178: checkcast     #91                 // class java/lang/Character
     181: invokevirtual #95                 // Method java/lang/Character.charValue:()C
     184: istore        9
     186: aload         8
     188: invokeinterface #98,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     193: checkcast     #100                // class java/lang/Number
     196: invokevirtual #103                // Method java/lang/Number.intValue:()I
     199: istore        10
     201: aload         6
     203: iload         9
     205: invokestatic  #107                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     208: invokeinterface #111,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     213: checkcast     #113                // class java/lang/Integer
     216: dup
     217: ifnull        226
     220: invokevirtual #114                // Method java/lang/Integer.intValue:()I
     223: goto          228
     226: pop
     227: iconst_0
     228: istore        11
     230: iload         10
     232: iload         11
     234: isub
     235: invokestatic  #120                // Method java/lang/Math.abs:(I)I
     238: iconst_3
     239: if_icmple     149
     242: iconst_0
     243: ireturn
     244: aload         6
     246: invokeinterface #68,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     251: invokeinterface #74,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     256: astore        7
     258: aload         7
     260: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     265: ifeq          353
     268: aload         7
     270: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     275: checkcast     #86                 // class java/util/Map$Entry
     278: astore        8
     280: aload         8
     282: invokeinterface #89,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     287: checkcast     #91                 // class java/lang/Character
     290: invokevirtual #95                 // Method java/lang/Character.charValue:()C
     293: istore        9
     295: aload         8
     297: invokeinterface #98,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     302: checkcast     #100                // class java/lang/Number
     305: invokevirtual #103                // Method java/lang/Number.intValue:()I
     308: istore        10
     310: aload         5
     312: iload         9
     314: invokestatic  #107                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     317: invokeinterface #111,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     322: checkcast     #113                // class java/lang/Integer
     325: dup
     326: ifnull        335
     329: invokevirtual #114                // Method java/lang/Integer.intValue:()I
     332: goto          337
     335: pop
     336: iconst_0
     337: istore        11
     339: iload         10
     341: iload         11
     343: isub
     344: invokestatic  #120                // Method java/lang/Math.abs:(I)I
     347: iconst_3
     348: if_icmple     258
     351: iconst_0
     352: ireturn
     353: iconst_1
     354: ireturn
}