package ru.amai.study.hackerrank.practice.interviewPreparationKit.dynamic.candies

import java.util.*
import kotlin.math.max
import kotlin.math.min

fun candies(grades: Array<Int>): Long {
    val size = grades.size

    val gradeByIndex = saveGrading(grades)

    val startIndicesWithDirections = buildStartIndicesWithDirections(gradeByIndex, size)
    val stopIndicesSet = buildStopIndicesSet(gradeByIndex, size)

    fun canMove(index: Int, direction: Direction): Boolean = when (direction) {
        Direction.LEFT -> index > 0
        Direction.RIGHT -> index < size - 1
    }

    val candiesDistribution = Array(size) { 1 }
    fun expandFrom(startIndex: Int, direction: Direction) {
        var currentIndx = startIndex
        while (currentIndx !in stopIndicesSet && canMove(currentIndx, direction)) {
            val currentCandies = candiesDistribution[currentIndx]
            currentIndx = direction.next(currentIndx)
            candiesDistribution[currentIndx] = max(currentCandies + 1, candiesDistribution[currentIndx])
        }
    }

    startIndicesWithDirections.forEach { (startIndex, directions) ->
        directions.forEach { direction -> expandFrom(startIndex, direction) }
    }

    return candiesDistribution.fold(0L) { acc, i -> acc + i }
}

private fun saveGrading(grades: Array<Int>): (Int) -> Int = { index -> when {
    index < 0 -> Int.MAX_VALUE
    index >= grades.size -> Int.MAX_VALUE
    else -> grades[index]
} }

private fun buildStartIndicesWithDirections(gradeByIndex: (Int) -> Int, size: Int): List<Pair<Int, List<Direction>>> =
    (0 until size).filter { index ->
        gradeByIndex(index) <= min(gradeByIndex(index - 1), gradeByIndex(index + 1))
    }.map { index -> when {
        gradeByIndex(index) == gradeByIndex(index + 1) -> index to listOf(Direction.LEFT)
        gradeByIndex(index) == gradeByIndex(index - 1) -> index to listOf(Direction.RIGHT)
        else -> index to listOf(Direction.LEFT, Direction.RIGHT)
    } }

private fun buildStopIndicesSet(gradeByIndex: (Int) -> Int, size: Int): Set<Int> =
    (0 until size).filter { index ->
        gradeByIndex(index) >= max(gradeByIndex(index - 1), gradeByIndex(index + 1))
    }.toSet()

enum class Direction {
    LEFT,
    RIGHT
}

fun Direction.next(index: Int): Int = when (this) {
    Direction.LEFT -> index - 1
    Direction.RIGHT -> index + 1
}

fun main() {
    val scan = Scanner(System.`in`)

    val n = scan.nextLine().trim().toInt()

    val arr = Array(n) { 0 }
    for (i in 0 until n) {
        val arrItem = scan.nextLine().trim().toInt()
        arr[i] = arrItem
    }

    val result = candies(arr)

    println(result)
}

Compiled from "Candies.kt"
public final class ru.amai.study.hackerrank.practice.interviewPreparationKit.dynamic.candies.CandiesKt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.values:()[Lru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.LEFT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;
      12: invokevirtual #22                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.RIGHT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;
      26: invokevirtual #22                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: aload_0
      36: putstatic     #29                 // Field $EnumSwitchMapping$0:[I
      39: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
}

Compiled from "Candies.kt"
public final class ru.amai.study.hackerrank.practice.interviewPreparationKit.dynamic.candies.CandiesKt {
  public static final long candies(java.lang.Integer[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String grades
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: arraylength
       8: istore_1
       9: aload_0
      10: invokestatic  #19                 // Method saveGrading:([Ljava/lang/Integer;)Lkotlin/jvm/functions/Function1;
      13: astore_2
      14: aload_2
      15: iload_1
      16: invokestatic  #23                 // Method buildStartIndicesWithDirections:(Lkotlin/jvm/functions/Function1;I)Ljava/util/List;
      19: astore_3
      20: aload_2
      21: iload_1
      22: invokestatic  #27                 // Method buildStopIndicesSet:(Lkotlin/jvm/functions/Function1;I)Ljava/util/Set;
      25: astore        4
      27: iconst_0
      28: istore        6
      30: iload_1
      31: anewarray     #29                 // class java/lang/Integer
      34: astore        7
      36: iload         6
      38: iload_1
      39: if_icmpge     61
      42: iload         6
      44: istore        9
      46: aload         7
      48: iload         9
      50: iconst_1
      51: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: aastore
      55: iinc          6, 1
      58: goto          36
      61: aload         7
      63: astore        5
      65: aload_3
      66: checkcast     #35                 // class java/lang/Iterable
      69: astore        6
      71: iconst_0
      72: istore        7
      74: aload         6
      76: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      81: astore        9
      83: aload         9
      85: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      90: ifeq          205
      93: aload         9
      95: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     100: astore        10
     102: aload         10
     104: checkcast     #51                 // class kotlin/Pair
     107: astore        12
     109: iconst_0
     110: istore        13
     112: aload         12
     114: invokevirtual #54                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     117: checkcast     #56                 // class java/lang/Number
     120: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     123: istore        14
     125: aload         12
     127: invokevirtual #63                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     130: checkcast     #65                 // class java/util/List
     133: astore        15
     135: aload         15
     137: checkcast     #35                 // class java/lang/Iterable
     140: astore        16
     142: iconst_0
     143: istore        17
     145: aload         16
     147: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     152: astore        18
     154: aload         18
     156: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     161: ifeq          199
     164: aload         18
     166: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     171: astore        19
     173: aload         19
     175: checkcast     #67                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction
     178: astore        20
     180: iconst_0
     181: istore        21
     183: aload         4
     185: aload         5
     187: iload_1
     188: iload         14
     190: aload         20
     192: invokestatic  #71                 // Method candies$expandFrom:(Ljava/util/Set;[Ljava/lang/Integer;IILru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;)V
     195: nop
     196: goto          154
     199: nop
     200: nop
     201: nop
     202: goto          83
     205: nop
     206: aload         5
     208: astore        6
     210: lconst_0
     211: lstore        7
     213: iconst_0
     214: istore        9
     216: lload         7
     218: lstore        10
     220: iconst_0
     221: istore        12
     223: aload         6
     225: arraylength
     226: istore        13
     228: iload         12
     230: iload         13
     232: if_icmpge     273
     235: aload         6
     237: iload         12
     239: aaload
     240: astore        14
     242: lload         10
     244: aload         14
     246: checkcast     #56                 // class java/lang/Number
     249: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     252: istore        15
     254: lstore        16
     256: iconst_0
     257: istore        18
     259: lload         16
     261: iload         15
     263: i2l
     264: ladd
     265: lstore        10
     267: iinc          12, 1
     270: goto          228
     273: lload         10
     275: lreturn

  private static final kotlin.jvm.functions.Function1<java.lang.Integer, java.lang.Integer> saveGrading(java.lang.Integer[]);
    Code:
       0: aload_0
       1: invokedynamic #126,  0            // InvokeDynamic #0:invoke:([Ljava/lang/Integer;)Lkotlin/jvm/functions/Function1;
       6: areturn

  private static final java.util.List<kotlin.Pair<java.lang.Integer, java.util.List<ru.amai.study.hackerrank.practice.interviewPreparationKit.dynamic.candies.Direction>>> buildStartIndicesWithDirections(kotlin.jvm.functions.Function1<? super java.lang.Integer, java.lang.Integer>, int);
    Code:
       0: iconst_0
       1: iload_1
       2: invokestatic  #133                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       5: checkcast     #35                 // class java/lang/Iterable
       8: astore_2
       9: iconst_0
      10: istore_3
      11: aload_2
      12: astore        4
      14: new           #135                // class java/util/ArrayList
      17: dup
      18: invokespecial #139                // Method java/util/ArrayList."<init>":()V
      21: checkcast     #141                // class java/util/Collection
      24: astore        5
      26: iconst_0
      27: istore        6
      29: aload         4
      31: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        7
      38: aload         7
      40: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          152
      48: aload         7
      50: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        8
      57: aload         8
      59: checkcast     #56                 // class java/lang/Number
      62: invokevirtual #60                 // Method java/lang/Number.intValue:()I
      65: istore        9
      67: iconst_0
      68: istore        10
      70: aload_0
      71: iload         9
      73: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      81: checkcast     #56                 // class java/lang/Number
      84: invokevirtual #60                 // Method java/lang/Number.intValue:()I
      87: aload_0
      88: iload         9
      90: iconst_1
      91: isub
      92: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     100: checkcast     #56                 // class java/lang/Number
     103: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     106: aload_0
     107: iload         9
     109: iconst_1
     110: iadd
     111: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     119: checkcast     #56                 // class java/lang/Number
     122: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     125: invokestatic  #149                // Method java/lang/Math.min:(II)I
     128: if_icmpgt     135
     131: iconst_1
     132: goto          136
     135: iconst_0
     136: ifeq          38
     139: aload         5
     141: aload         8
     143: invokeinterface #153,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     148: pop
     149: goto          38
     152: aload         5
     154: checkcast     #65                 // class java/util/List
     157: nop
     158: checkcast     #35                 // class java/lang/Iterable
     161: astore_2
     162: nop
     163: iconst_0
     164: istore_3
     165: aload_2
     166: astore        4
     168: new           #135                // class java/util/ArrayList
     171: dup
     172: aload_2
     173: bipush        10
     175: invokestatic  #159                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     178: invokespecial #162                // Method java/util/ArrayList."<init>":(I)V
     181: checkcast     #141                // class java/util/Collection
     184: astore        5
     186: iconst_0
     187: istore        6
     189: aload         4
     191: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     196: astore        7
     198: aload         7
     200: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     205: ifeq          393
     208: aload         7
     210: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     215: astore        8
     217: aload         5
     219: aload         8
     221: checkcast     #56                 // class java/lang/Number
     224: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     227: istore        9
     229: astore        12
     231: iconst_0
     232: istore        10
     234: nop
     235: aload_0
     236: iload         9
     238: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     241: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     246: checkcast     #56                 // class java/lang/Number
     249: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     252: aload_0
     253: iload         9
     255: iconst_1
     256: iadd
     257: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     260: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     265: checkcast     #56                 // class java/lang/Number
     268: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     271: if_icmpne     291
     274: iload         9
     276: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     279: getstatic     #165                // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.LEFT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;
     282: invokestatic  #169                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     285: invokestatic  #175                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     288: goto          380
     291: aload_0
     292: iload         9
     294: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     297: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     302: checkcast     #56                 // class java/lang/Number
     305: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     308: aload_0
     309: iload         9
     311: iconst_1
     312: isub
     313: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     316: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     321: checkcast     #56                 // class java/lang/Number
     324: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     327: if_icmpne     347
     330: iload         9
     332: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     335: getstatic     #178                // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.RIGHT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;
     338: invokestatic  #169                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     341: invokestatic  #175                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     344: goto          380
     347: iload         9
     349: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     352: iconst_2
     353: anewarray     #67                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction
     356: astore        11
     358: aload         11
     360: iconst_0
     361: getstatic     #165                // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.LEFT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;
     364: aastore
     365: aload         11
     367: iconst_1
     368: getstatic     #178                // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.RIGHT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;
     371: aastore
     372: aload         11
     374: invokestatic  #181                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     377: invokestatic  #175                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     380: nop
     381: aload         12
     383: swap
     384: invokeinterface #153,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     389: pop
     390: goto          198
     393: aload         5
     395: checkcast     #65                 // class java/util/List
     398: nop
     399: areturn

  private static final java.util.Set<java.lang.Integer> buildStopIndicesSet(kotlin.jvm.functions.Function1<? super java.lang.Integer, java.lang.Integer>, int);
    Code:
       0: iconst_0
       1: iload_1
       2: invokestatic  #133                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       5: checkcast     #35                 // class java/lang/Iterable
       8: astore_2
       9: iconst_0
      10: istore_3
      11: aload_2
      12: astore        4
      14: new           #135                // class java/util/ArrayList
      17: dup
      18: invokespecial #139                // Method java/util/ArrayList."<init>":()V
      21: checkcast     #141                // class java/util/Collection
      24: astore        5
      26: iconst_0
      27: istore        6
      29: aload         4
      31: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        7
      38: aload         7
      40: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          152
      48: aload         7
      50: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        8
      57: aload         8
      59: checkcast     #56                 // class java/lang/Number
      62: invokevirtual #60                 // Method java/lang/Number.intValue:()I
      65: istore        9
      67: iconst_0
      68: istore        10
      70: aload_0
      71: iload         9
      73: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      81: checkcast     #56                 // class java/lang/Number
      84: invokevirtual #60                 // Method java/lang/Number.intValue:()I
      87: aload_0
      88: iload         9
      90: iconst_1
      91: isub
      92: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     100: checkcast     #56                 // class java/lang/Number
     103: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     106: aload_0
     107: iload         9
     109: iconst_1
     110: iadd
     111: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: invokeinterface #143,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     119: checkcast     #56                 // class java/lang/Number
     122: invokevirtual #60                 // Method java/lang/Number.intValue:()I
     125: invokestatic  #200                // Method java/lang/Math.max:(II)I
     128: if_icmplt     135
     131: iconst_1
     132: goto          136
     135: iconst_0
     136: ifeq          38
     139: aload         5
     141: aload         8
     143: invokeinterface #153,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     148: pop
     149: goto          38
     152: aload         5
     154: checkcast     #65                 // class java/util/List
     157: nop
     158: checkcast     #35                 // class java/lang/Iterable
     161: invokestatic  #204                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     164: areturn

  public static final int next(ru.amai.study.hackerrank.practice.interviewPreparationKit.dynamic.candies.Direction, int);
    Code:
       0: aload_0
       1: ldc           #208                // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getstatic     #214                // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/CandiesKt$WhenMappings.$EnumSwitchMapping$0:[I
      10: swap
      11: invokevirtual #217                // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.ordinal:()I
      14: iaload
      15: tableswitch   { // 1 to 2
                     1: 36
                     2: 42
               default: 48
          }
      36: iload_1
      37: iconst_1
      38: isub
      39: goto          56
      42: iload_1
      43: iconst_1
      44: iadd
      45: goto          56
      48: new           #219                // class kotlin/NoWhenBranchMatchedException
      51: dup
      52: invokespecial #220                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
      55: athrow
      56: ireturn

  public static final void main();
    Code:
       0: new           #224                // class java/util/Scanner
       3: dup
       4: getstatic     #230                // Field java/lang/System.in:Ljava/io/InputStream;
       7: invokespecial #233                // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      10: astore_0
      11: aload_0
      12: invokevirtual #237                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      15: dup
      16: ldc           #239                // String nextLine(...)
      18: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: checkcast     #244                // class java/lang/CharSequence
      24: invokestatic  #250                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      27: invokevirtual #253                // Method java/lang/Object.toString:()Ljava/lang/String;
      30: invokestatic  #257                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      33: istore_1
      34: iconst_0
      35: istore_3
      36: iload_1
      37: anewarray     #29                 // class java/lang/Integer
      40: astore        4
      42: iload_3
      43: iload_1
      44: if_icmpge     65
      47: iload_3
      48: istore        5
      50: aload         4
      52: iload         5
      54: iconst_0
      55: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      58: aastore
      59: iinc          3, 1
      62: goto          42
      65: aload         4
      67: astore_2
      68: iconst_0
      69: istore_3
      70: iload_3
      71: iload_1
      72: if_icmpge     113
      75: aload_0
      76: invokevirtual #237                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      79: dup
      80: ldc           #239                // String nextLine(...)
      82: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      85: checkcast     #244                // class java/lang/CharSequence
      88: invokestatic  #250                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      91: invokevirtual #253                // Method java/lang/Object.toString:()Ljava/lang/String;
      94: invokestatic  #257                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      97: istore        4
      99: aload_2
     100: iload_3
     101: iload         4
     103: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: aastore
     107: iinc          3, 1
     110: goto          70
     113: aload_2
     114: invokestatic  #259                // Method candies:([Ljava/lang/Integer;)J
     117: lstore_3
     118: getstatic     #263                // Field java/lang/System.out:Ljava/io/PrintStream;
     121: lload_3
     122: invokevirtual #269                // Method java/io/PrintStream.println:(J)V
     125: return

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

  private static final boolean candies$canMove(int, int, ru.amai.study.hackerrank.practice.interviewPreparationKit.dynamic.candies.Direction);
    Code:
       0: aload_2
       1: getstatic     #214                // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/CandiesKt$WhenMappings.$EnumSwitchMapping$0:[I
       4: swap
       5: invokevirtual #217                // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction.ordinal:()I
       8: iaload
       9: tableswitch   { // 1 to 2
                     1: 32
                     2: 44
               default: 59
          }
      32: iload_1
      33: ifle          40
      36: iconst_1
      37: goto          67
      40: iconst_0
      41: goto          67
      44: iload_1
      45: iload_0
      46: iconst_1
      47: isub
      48: if_icmpge     55
      51: iconst_1
      52: goto          67
      55: iconst_0
      56: goto          67
      59: new           #219                // class kotlin/NoWhenBranchMatchedException
      62: dup
      63: invokespecial #220                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
      66: athrow
      67: ireturn

  private static final void candies$expandFrom(java.util.Set<java.lang.Integer>, java.lang.Integer[], int, int, ru.amai.study.hackerrank.practice.interviewPreparationKit.dynamic.candies.Direction);
    Code:
       0: iload_3
       1: istore        5
       3: aload_0
       4: iload         5
       6: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       9: invokeinterface #286,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      14: ifne          70
      17: iload_2
      18: iload         5
      20: aload         4
      22: invokestatic  #288                // Method candies$canMove:(IILru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;)Z
      25: ifeq          70
      28: aload_1
      29: iload         5
      31: aaload
      32: invokevirtual #289                // Method java/lang/Integer.intValue:()I
      35: istore        6
      37: aload         4
      39: iload         5
      41: invokestatic  #291                // Method next:(Lru/amai/study/hackerrank/practice/interviewPreparationKit/dynamic/candies/Direction;I)I
      44: istore        5
      46: aload_1
      47: iload         5
      49: iload         6
      51: iconst_1
      52: iadd
      53: aload_1
      54: iload         5
      56: aaload
      57: invokevirtual #289                // Method java/lang/Integer.intValue:()I
      60: invokestatic  #200                // Method java/lang/Math.max:(II)I
      63: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: aastore
      67: goto          3
      70: return

  private static final int saveGrading$lambda$3(java.lang.Integer[], int);
    Code:
       0: nop
       1: iload_1
       2: ifge          11
       5: ldc_w         #294                // int 2147483647
       8: goto          29
      11: iload_1
      12: aload_0
      13: arraylength
      14: if_icmplt     23
      17: ldc_w         #294                // int 2147483647
      20: goto          29
      23: aload_0
      24: iload_1
      25: aaload
      26: invokevirtual #289                // Method java/lang/Integer.intValue:()I
      29: ireturn
}


package ru.amai.study.hackerrank.practice.interviewPreparationKit.hashmaps.triplets

import java.util.*

fun countTriplets(array: LongArray, ratio: Long): Long {
    fun modR(iv: IndexedValue<Long>) = iv.value % ratio == 0L
    fun divR(iv: IndexedValue<Long>) = IndexedValue(iv.index, iv.value / ratio)

    fun List<IndexedValue<Long>>.indexes() = map { (index, _) -> index }

    fun candidates(power: Int) =
        (0 until power).fold(array.withIndex()) { curArr, _ ->
            curArr.filter(::modR).map(::divR)
        }.groupBy { (_, value) -> value }
         .mapValues { (_, indexedValues) -> indexedValues.indexes() }

    val (iCandidates, jCandidates, kCandidates) =
        listOf(0, 1, 2).map(::candidates)

    val commonBases = kCandidates.keys.filter { v ->
        (v in iCandidates) && (v in jCandidates)
    }

    return commonBases.map { v ->
        val kvCandidates = kCandidates.getValue(v)
        val jvCandidates = jCandidates.getValue(v)
        val ivCandidates = iCandidates.getValue(v)

        countTriplesForSingleBaseValue(ivCandidates, jvCandidates, kvCandidates)
    }.sum()
}

private fun countTriplesForSingleBaseValue(
    ivCandidates: List<Int>,
    jvCandidates: List<Int>,
    kvCandidates: List<Int>
): Long {
    var i = 0
    var j = 0
    var k = 0
    var iCnt = 0L
    var jCnt = 0L
    var kCnt = 0L

    while ((k < kvCandidates.size) && (i < ivCandidates.size) && (j < jvCandidates.size)) {
        val ivc = ivCandidates[i]
        val jvc = jvCandidates[j]
        val kvc = kvCandidates[k]

        when {
            kvc <= jvc -> {
                kCnt += jCnt
                k++
            }
            jvc <= ivc -> {
                jCnt += iCnt
                j++
            }
            else -> {
                i++
                iCnt += 1L
            }
        }
    }

    while ((k < kvCandidates.size) && (j < jvCandidates.size)) {
        val jvc = jvCandidates[j]
        val kvc = kvCandidates[k]

        when {
            kvc <= jvc -> {
                kCnt += jCnt
                k++
            }
            else -> {
                jCnt += iCnt
                j++
            }
        }
    }

    if ((k < kvCandidates.size) && (kvCandidates[k] > jvCandidates.last())) {
        kCnt += jCnt * (kvCandidates.size - k)
    }

    return kCnt
}

fun main() {
    val scanner = Scanner(System.`in`)
    val nr = scanner.nextLine().trim().split(" ")

    val r = nr[1].toLong()
    val array = scanner.nextLine().trim().split(" ").map { it.toLong() }.toLongArray()

    val result = countTriplets(array, r)
    println(result)
}

Compiled from "CountTriplets.kt"
public final class ru.amai.study.hackerrank.practice.interviewPreparationKit.hashmaps.triplets.CountTripletsKt {
  public static final long countTriplets(long[], long);
    Code:
       0: aload_0
       1: ldc           #9                  // String array
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_3
       7: anewarray     #17                 // class java/lang/Integer
      10: astore        4
      12: aload         4
      14: iconst_0
      15: iconst_0
      16: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      19: aastore
      20: aload         4
      22: iconst_1
      23: iconst_1
      24: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      27: aastore
      28: aload         4
      30: iconst_2
      31: iconst_2
      32: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: aastore
      36: aload         4
      38: invokestatic  #27                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      41: checkcast     #29                 // class java/lang/Iterable
      44: astore        4
      46: iconst_0
      47: istore        5
      49: aload         4
      51: astore        6
      53: new           #31                 // class java/util/ArrayList
      56: dup
      57: aload         4
      59: bipush        10
      61: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      64: invokespecial #39                 // Method java/util/ArrayList."<init>":(I)V
      67: checkcast     #41                 // class java/util/Collection
      70: astore        7
      72: iconst_0
      73: istore        8
      75: aload         6
      77: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      82: astore        9
      84: aload         9
      86: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      91: ifeq          139
      94: aload         9
      96: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     101: astore        10
     103: aload         7
     105: aload         10
     107: checkcast     #57                 // class java/lang/Number
     110: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     113: istore        11
     115: astore        21
     117: iconst_0
     118: istore        12
     120: aload_0
     121: lload_1
     122: iload         11
     124: invokestatic  #65                 // Method countTriplets$candidates:([JJI)Ljava/util/Map;
     127: aload         21
     129: swap
     130: invokeinterface #69,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     135: pop
     136: goto          84
     139: aload         7
     141: checkcast     #71                 // class java/util/List
     144: nop
     145: astore_3
     146: aload_3
     147: iconst_0
     148: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     153: checkcast     #77                 // class java/util/Map
     156: astore        4
     158: aload_3
     159: iconst_1
     160: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     165: checkcast     #77                 // class java/util/Map
     168: astore        5
     170: aload_3
     171: iconst_2
     172: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     177: checkcast     #77                 // class java/util/Map
     180: astore        6
     182: aload         6
     184: invokeinterface #81,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     189: checkcast     #29                 // class java/lang/Iterable
     192: astore        8
     194: iconst_0
     195: istore        9
     197: aload         8
     199: astore        10
     201: new           #31                 // class java/util/ArrayList
     204: dup
     205: invokespecial #84                 // Method java/util/ArrayList."<init>":()V
     208: checkcast     #41                 // class java/util/Collection
     211: astore        11
     213: iconst_0
     214: istore        12
     216: aload         10
     218: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     223: astore        13
     225: aload         13
     227: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     232: ifeq          310
     235: aload         13
     237: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     242: astore        14
     244: aload         14
     246: checkcast     #57                 // class java/lang/Number
     249: invokevirtual #88                 // Method java/lang/Number.longValue:()J
     252: lstore        15
     254: iconst_0
     255: istore        17
     257: lload         15
     259: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     262: aload         4
     264: swap
     265: invokeinterface #96,  2           // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     270: ifeq          293
     273: lload         15
     275: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     278: aload         5
     280: swap
     281: invokeinterface #96,  2           // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     286: ifeq          293
     289: iconst_1
     290: goto          294
     293: iconst_0
     294: ifeq          225
     297: aload         11
     299: aload         14
     301: invokeinterface #69,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     306: pop
     307: goto          225
     310: aload         11
     312: checkcast     #71                 // class java/util/List
     315: nop
     316: astore        7
     318: aload         7
     320: checkcast     #29                 // class java/lang/Iterable
     323: astore        8
     325: iconst_0
     326: istore        9
     328: aload         8
     330: astore        10
     332: new           #31                 // class java/util/ArrayList
     335: dup
     336: aload         8
     338: bipush        10
     340: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     343: invokespecial #39                 // Method java/util/ArrayList."<init>":(I)V
     346: checkcast     #41                 // class java/util/Collection
     349: astore        11
     351: iconst_0
     352: istore        12
     354: aload         10
     356: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     361: astore        13
     363: aload         13
     365: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     370: ifeq          468
     373: aload         13
     375: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     380: astore        14
     382: aload         11
     384: aload         14
     386: checkcast     #57                 // class java/lang/Number
     389: invokevirtual #88                 // Method java/lang/Number.longValue:()J
     392: lstore        15
     394: astore        21
     396: iconst_0
     397: istore        17
     399: aload         6
     401: lload         15
     403: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     406: invokestatic  #102                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     409: checkcast     #71                 // class java/util/List
     412: astore        18
     414: aload         5
     416: lload         15
     418: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     421: invokestatic  #102                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     424: checkcast     #71                 // class java/util/List
     427: astore        19
     429: aload         4
     431: lload         15
     433: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     436: invokestatic  #102                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     439: checkcast     #71                 // class java/util/List
     442: astore        20
     444: aload         20
     446: aload         19
     448: aload         18
     450: invokestatic  #106                // Method countTriplesForSingleBaseValue:(Ljava/util/List;Ljava/util/List;Ljava/util/List;)J
     453: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     456: aload         21
     458: swap
     459: invokeinterface #69,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     464: pop
     465: goto          363
     468: aload         11
     470: checkcast     #71                 // class java/util/List
     473: nop
     474: checkcast     #29                 // class java/lang/Iterable
     477: invokestatic  #110                // Method kotlin/collections/CollectionsKt.sumOfLong:(Ljava/lang/Iterable;)J
     480: lreturn

  private static final long countTriplesForSingleBaseValue(java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>, java.util.List<java.lang.Integer>);
    Code:
       0: iconst_0
       1: istore_3
       2: iconst_0
       3: istore        4
       5: iconst_0
       6: istore        5
       8: lconst_0
       9: lstore        6
      11: lconst_0
      12: lstore        8
      14: lconst_0
      15: lstore        10
      17: iload         5
      19: aload_2
      20: invokeinterface #147,  1          // InterfaceMethod java/util/List.size:()I
      25: if_icmpge     155
      28: iload_3
      29: aload_0
      30: invokeinterface #147,  1          // InterfaceMethod java/util/List.size:()I
      35: if_icmpge     155
      38: iload         4
      40: aload_1
      41: invokeinterface #147,  1          // InterfaceMethod java/util/List.size:()I
      46: if_icmpge     155
      49: aload_0
      50: iload_3
      51: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      56: checkcast     #57                 // class java/lang/Number
      59: invokevirtual #61                 // Method java/lang/Number.intValue:()I
      62: istore        12
      64: aload_1
      65: iload         4
      67: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      72: checkcast     #57                 // class java/lang/Number
      75: invokevirtual #61                 // Method java/lang/Number.intValue:()I
      78: istore        13
      80: aload_2
      81: iload         5
      83: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #57                 // class java/lang/Number
      91: invokevirtual #61                 // Method java/lang/Number.intValue:()I
      94: istore        14
      96: nop
      97: iload         14
      99: iload         13
     101: if_icmpgt     120
     104: lload         10
     106: lload         8
     108: ladd
     109: lstore        10
     111: iload         5
     113: iinc          5, 1
     116: pop
     117: goto          17
     120: iload         13
     122: iload         12
     124: if_icmpgt     143
     127: lload         8
     129: lload         6
     131: ladd
     132: lstore        8
     134: iload         4
     136: iinc          4, 1
     139: pop
     140: goto          17
     143: iinc          3, 1
     146: lload         6
     148: lconst_1
     149: ladd
     150: lstore        6
     152: goto          17
     155: iload         5
     157: aload_2
     158: invokeinterface #147,  1          // InterfaceMethod java/util/List.size:()I
     163: if_icmpge     243
     166: iload         4
     168: aload_1
     169: invokeinterface #147,  1          // InterfaceMethod java/util/List.size:()I
     174: if_icmpge     243
     177: aload_1
     178: iload         4
     180: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     185: checkcast     #57                 // class java/lang/Number
     188: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     191: istore        12
     193: aload_2
     194: iload         5
     196: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     201: checkcast     #57                 // class java/lang/Number
     204: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     207: istore        13
     209: nop
     210: iload         13
     212: iload         12
     214: if_icmpgt     230
     217: lload         10
     219: lload         8
     221: ladd
     222: lstore        10
     224: iinc          5, 1
     227: goto          155
     230: lload         8
     232: lload         6
     234: ladd
     235: lstore        8
     237: iinc          4, 1
     240: goto          155
     243: iload         5
     245: aload_2
     246: invokeinterface #147,  1          // InterfaceMethod java/util/List.size:()I
     251: if_icmpge     299
     254: aload_2
     255: iload         5
     257: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     262: checkcast     #57                 // class java/lang/Number
     265: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     268: aload_1
     269: invokestatic  #151                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     272: checkcast     #57                 // class java/lang/Number
     275: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     278: if_icmple     299
     281: lload         10
     283: lload         8
     285: aload_2
     286: invokeinterface #147,  1          // InterfaceMethod java/util/List.size:()I
     291: iload         5
     293: isub
     294: i2l
     295: lmul
     296: ladd
     297: lstore        10
     299: lload         10
     301: lreturn

  public static final void main();
    Code:
       0: new           #163                // class java/util/Scanner
       3: dup
       4: getstatic     #169                // Field java/lang/System.in:Ljava/io/InputStream;
       7: invokespecial #172                // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      10: astore_0
      11: aload_0
      12: invokevirtual #176                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      15: dup
      16: ldc           #178                // String nextLine(...)
      18: invokestatic  #181                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: checkcast     #183                // class java/lang/CharSequence
      24: invokestatic  #189                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      27: invokevirtual #192                // Method java/lang/Object.toString:()Ljava/lang/String;
      30: checkcast     #183                // class java/lang/CharSequence
      33: iconst_1
      34: anewarray     #194                // class java/lang/String
      37: astore_2
      38: aload_2
      39: iconst_0
      40: ldc           #196                // String
      42: aastore
      43: aload_2
      44: iconst_0
      45: iconst_0
      46: bipush        6
      48: aconst_null
      49: invokestatic  #200                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      52: astore_1
      53: aload_1
      54: iconst_1
      55: invokeinterface #75,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #194                // class java/lang/String
      63: invokestatic  #204                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      66: lstore_2
      67: aload_0
      68: invokevirtual #176                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      71: dup
      72: ldc           #178                // String nextLine(...)
      74: invokestatic  #181                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      77: checkcast     #183                // class java/lang/CharSequence
      80: invokestatic  #189                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      83: invokevirtual #192                // Method java/lang/Object.toString:()Ljava/lang/String;
      86: checkcast     #183                // class java/lang/CharSequence
      89: iconst_1
      90: anewarray     #194                // class java/lang/String
      93: astore        5
      95: aload         5
      97: iconst_0
      98: ldc           #196                // String
     100: aastore
     101: aload         5
     103: iconst_0
     104: iconst_0
     105: bipush        6
     107: aconst_null
     108: invokestatic  #200                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     111: checkcast     #29                 // class java/lang/Iterable
     114: astore        5
     116: iconst_0
     117: istore        6
     119: aload         5
     121: astore        7
     123: new           #31                 // class java/util/ArrayList
     126: dup
     127: aload         5
     129: bipush        10
     131: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     134: invokespecial #39                 // Method java/util/ArrayList."<init>":(I)V
     137: checkcast     #41                 // class java/util/Collection
     140: astore        8
     142: iconst_0
     143: istore        9
     145: aload         7
     147: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     152: astore        10
     154: aload         10
     156: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     161: ifeq          208
     164: aload         10
     166: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     171: astore        11
     173: aload         8
     175: aload         11
     177: checkcast     #194                // class java/lang/String
     180: astore        12
     182: astore        14
     184: iconst_0
     185: istore        13
     187: aload         12
     189: invokestatic  #204                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     192: nop
     193: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     196: aload         14
     198: swap
     199: invokeinterface #69,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     204: pop
     205: goto          154
     208: aload         8
     210: checkcast     #71                 // class java/util/List
     213: nop
     214: checkcast     #41                 // class java/util/Collection
     217: invokestatic  #208                // Method kotlin/collections/CollectionsKt.toLongArray:(Ljava/util/Collection;)[J
     220: astore        4
     222: aload         4
     224: lload_2
     225: invokestatic  #210                // Method countTriplets:([JJ)J
     228: lstore        5
     230: getstatic     #214                // Field java/lang/System.out:Ljava/io/PrintStream;
     233: lload         5
     235: invokevirtual #220                // Method java/io/PrintStream.println:(J)V
     238: return

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

  private static final boolean countTriplets$modR(long, kotlin.collections.IndexedValue<java.lang.Long>);
    Code:
       0: aload_2
       1: invokevirtual #240                // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
       4: checkcast     #57                 // class java/lang/Number
       7: invokevirtual #88                 // Method java/lang/Number.longValue:()J
      10: lload_0
      11: lrem
      12: lconst_0
      13: lcmp
      14: ifne          21
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ireturn

  private static final kotlin.collections.IndexedValue<java.lang.Long> countTriplets$divR(long, kotlin.collections.IndexedValue<java.lang.Long>);
    Code:
       0: new           #238                // class kotlin/collections/IndexedValue
       3: dup
       4: aload_2
       5: invokevirtual #249                // Method kotlin/collections/IndexedValue.getIndex:()I
       8: aload_2
       9: invokevirtual #240                // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
      12: checkcast     #57                 // class java/lang/Number
      15: invokevirtual #88                 // Method java/lang/Number.longValue:()J
      18: lload_0
      19: ldiv
      20: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      23: invokespecial #252                // Method kotlin/collections/IndexedValue."<init>":(ILjava/lang/Object;)V
      26: areturn

  private static final java.util.List<java.lang.Integer> countTriplets$indexes(java.util.List<kotlin.collections.IndexedValue<java.lang.Long>>);
    Code:
       0: aload_0
       1: checkcast     #29                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #31                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #39                 // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #41                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          95
      48: aload         6
      50: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #238                // class kotlin/collections/IndexedValue
      64: astore        8
      66: astore        11
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokevirtual #258                // Method kotlin/collections/IndexedValue.component1:()I
      76: istore        10
      78: iload         10
      80: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      83: aload         11
      85: swap
      86: invokeinterface #69,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: goto          38
      95: aload         4
      97: checkcast     #71                 // class java/util/List
     100: nop
     101: areturn

  private static final java.util.Map<java.lang.Long, java.util.List<java.lang.Integer>> countTriplets$candidates(long[], long, int);
    Code:
       0: iconst_0
       1: iload_3
       2: invokestatic  #268                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       5: checkcast     #29                 // class java/lang/Iterable
       8: astore        4
      10: aload_0
      11: invokestatic  #274                // Method kotlin/collections/ArraysKt.withIndex:([J)Ljava/lang/Iterable;
      14: astore        5
      16: iconst_0
      17: istore        6
      19: aload         5
      21: astore        7
      23: aload         4
      25: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      30: astore        8
      32: aload         8
      34: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          261
      42: aload         8
      44: checkcast     #276                // class kotlin/collections/IntIterator
      47: invokevirtual #279                // Method kotlin/collections/IntIterator.nextInt:()I
      50: istore        9
      52: aload         7
      54: astore        11
      56: iconst_0
      57: istore        12
      59: aload         11
      61: astore        13
      63: iconst_0
      64: istore        14
      66: aload         13
      68: astore        15
      70: new           #31                 // class java/util/ArrayList
      73: dup
      74: invokespecial #84                 // Method java/util/ArrayList."<init>":()V
      77: checkcast     #41                 // class java/util/Collection
      80: astore        16
      82: iconst_0
      83: istore        17
      85: aload         15
      87: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      92: astore        18
      94: aload         18
      96: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     101: ifeq          145
     104: aload         18
     106: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     111: astore        19
     113: aload         19
     115: checkcast     #238                // class kotlin/collections/IndexedValue
     118: astore        20
     120: iconst_0
     121: istore        21
     123: lload_1
     124: aload         20
     126: invokestatic  #281                // Method countTriplets$modR:(JLkotlin/collections/IndexedValue;)Z
     129: ifeq          94
     132: aload         16
     134: aload         19
     136: invokeinterface #69,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     141: pop
     142: goto          94
     145: aload         16
     147: checkcast     #71                 // class java/util/List
     150: nop
     151: checkcast     #29                 // class java/lang/Iterable
     154: astore        13
     156: nop
     157: iconst_0
     158: istore        14
     160: aload         13
     162: astore        15
     164: new           #31                 // class java/util/ArrayList
     167: dup
     168: aload         13
     170: bipush        10
     172: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     175: invokespecial #39                 // Method java/util/ArrayList."<init>":(I)V
     178: checkcast     #41                 // class java/util/Collection
     181: astore        16
     183: iconst_0
     184: istore        17
     186: aload         15
     188: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     193: astore        18
     195: aload         18
     197: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     202: ifeq          246
     205: aload         18
     207: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     212: astore        19
     214: aload         16
     216: aload         19
     218: checkcast     #238                // class kotlin/collections/IndexedValue
     221: astore        20
     223: astore        22
     225: iconst_0
     226: istore        21
     228: lload_1
     229: aload         20
     231: invokestatic  #283                // Method countTriplets$divR:(JLkotlin/collections/IndexedValue;)Lkotlin/collections/IndexedValue;
     234: aload         22
     236: swap
     237: invokeinterface #69,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     242: pop
     243: goto          195
     246: aload         16
     248: checkcast     #71                 // class java/util/List
     251: nop
     252: checkcast     #29                 // class java/lang/Iterable
     255: nop
     256: astore        7
     258: goto          32
     261: aload         7
     263: astore        4
     265: nop
     266: iconst_0
     267: istore        5
     269: aload         4
     271: astore        6
     273: new           #285                // class java/util/LinkedHashMap
     276: dup
     277: invokespecial #286                // Method java/util/LinkedHashMap."<init>":()V
     280: checkcast     #77                 // class java/util/Map
     283: astore        7
     285: iconst_0
     286: istore        8
     288: aload         6
     290: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     295: astore        9
     297: aload         9
     299: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     304: ifeq          422
     307: aload         9
     309: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     314: astore        10
     316: aload         10
     318: checkcast     #238                // class kotlin/collections/IndexedValue
     321: astore        11
     323: iconst_0
     324: istore        12
     326: aload         11
     328: invokevirtual #289                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     331: checkcast     #57                 // class java/lang/Number
     334: invokevirtual #88                 // Method java/lang/Number.longValue:()J
     337: lstore        13
     339: lload         13
     341: invokestatic  #93                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     344: astore        15
     346: aload         7
     348: astore        16
     350: iconst_0
     351: istore        17
     353: aload         16
     355: aload         15
     357: invokeinterface #292,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     362: astore        18
     364: aload         18
     366: ifnonnull     401
     369: iconst_0
     370: istore        19
     372: new           #31                 // class java/util/ArrayList
     375: dup
     376: invokespecial #84                 // Method java/util/ArrayList."<init>":()V
     379: checkcast     #71                 // class java/util/List
     382: astore        19
     384: aload         16
     386: aload         15
     388: aload         19
     390: invokeinterface #296,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     395: pop
     396: aload         19
     398: goto          403
     401: aload         18
     403: nop
     404: checkcast     #71                 // class java/util/List
     407: astore        11
     409: aload         11
     411: aload         10
     413: invokeinterface #297,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     418: pop
     419: goto          297
     422: aload         7
     424: nop
     425: astore        4
     427: nop
     428: iconst_0
     429: istore        5
     431: aload         4
     433: astore        6
     435: new           #285                // class java/util/LinkedHashMap
     438: dup
     439: aload         4
     441: invokeinterface #298,  1          // InterfaceMethod java/util/Map.size:()I
     446: invokestatic  #302                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     449: invokespecial #303                // Method java/util/LinkedHashMap."<init>":(I)V
     452: checkcast     #77                 // class java/util/Map
     455: astore        7
     457: iconst_0
     458: istore        8
     460: aload         6
     462: invokeinterface #306,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     467: checkcast     #29                 // class java/lang/Iterable
     470: astore        9
     472: iconst_0
     473: istore        10
     475: aload         9
     477: invokeinterface #45,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     482: astore        11
     484: aload         11
     486: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     491: ifeq          575
     494: aload         11
     496: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     501: astore        12
     503: aload         7
     505: aload         12
     507: checkcast     #308                // class java/util/Map$Entry
     510: astore        13
     512: astore        14
     514: iconst_0
     515: istore        15
     517: aload         13
     519: invokeinterface #311,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     524: aload         14
     526: swap
     527: aload         12
     529: checkcast     #308                // class java/util/Map$Entry
     532: astore        16
     534: astore        24
     536: astore        23
     538: iconst_0
     539: istore        17
     541: aload         16
     543: invokeinterface #312,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     548: checkcast     #71                 // class java/util/List
     551: astore        18
     553: aload         18
     555: invokestatic  #314                // Method countTriplets$indexes:(Ljava/util/List;)Ljava/util/List;
     558: astore        25
     560: aload         23
     562: aload         24
     564: aload         25
     566: invokeinterface #296,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     571: pop
     572: goto          484
     575: aload         7
     577: nop
     578: nop
     579: areturn
}


package ru.amai.study.hackerrank.practice.interviewPreparationKit.warmUpChallenges.clouds

import java.util.*

private const val MAX_CLOUDS = 100
private const val MIN_CLOUDS = 2

fun jumpingOnClouds(clouds: Array<Int>): Int {
    checkRequirement(clouds)

    fun isThunder(cloud: Int) = cloud == 1

    val (totalPenalty, _) = clouds.withIndex()
        .fold(0 to PenaltyState.EVEN) { (penalty, penaltyState), (indx, cloud) ->
            if (isThunder(cloud) && penaltyState.isApplicable(indx)) {
                (penalty + 1) to penaltyState.flip()
            } else penalty to penaltyState
        }

    return (clouds.size + totalPenalty) / 2
}

private fun checkRequirement(clouds: Array<Int>) {
    require(clouds.all { it in listOf(0, 1) }) {
        "clouds must be numbered 0 or 1; got ${clouds.contentToString()}"
    }
    require(clouds.size in MIN_CLOUDS..MAX_CLOUDS) {
        "number of clouds should be <= $MAX_CLOUDS and >= $MIN_CLOUDS; got ${clouds.size}"
    }
    require(clouds.first() == 0) { "first cloud should be 0; got ${clouds.first()}" }
    require(clouds.last() == 0) { "last cloud should be 0; got ${clouds.last()}" }
    require(
        clouds.toList()
            .zipWithNext()
            .map { (curr, next) -> curr + next }.all { it != 2 }
    ) { "there should not be two consecutive 1's in clouds; got ${clouds.contentToString()}" }
}

enum class PenaltyState {
    EVEN,
    ODD;

    fun flip() = when (this) {
        EVEN -> ODD
        ODD -> EVEN
    }

    fun isApplicable(indx: Int) = when (this) {
       EVEN -> indx % 2 == 0
       ODD -> indx % 2 == 1
    }
}

fun main() {
    val scanner = Scanner(System.`in`)
    scanner.nextLine().trim()
    val clouds = scanner.nextLine().split(" ").map { it.trim().toInt() }.toTypedArray()

    val result = jumpingOnClouds(clouds)
    println(result)
}

Compiled from "JumpingOnClouds.kt"
public final class ru.amai.study.hackerrank.practice.interviewPreparationKit.warmUpChallenges.clouds.JumpingOnCloudsKt {
  private static final int MAX_CLOUDS;

  private static final int MIN_CLOUDS;

  public static final int jumpingOnClouds(java.lang.Integer[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String clouds
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #19                 // Method checkRequirement:([Ljava/lang/Integer;)V
      10: aload_0
      11: invokestatic  #25                 // Method kotlin/collections/ArraysKt.withIndex:([Ljava/lang/Object;)Ljava/lang/Iterable;
      14: astore_1
      15: iconst_0
      16: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      19: getstatic     #37                 // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/warmUpChallenges/clouds/PenaltyState.EVEN:Lru/amai/study/hackerrank/practice/interviewPreparationKit/warmUpChallenges/clouds/PenaltyState;
      22: invokestatic  #43                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      25: astore_2
      26: iconst_0
      27: istore_3
      28: aload_2
      29: astore        4
      31: aload_1
      32: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          166
      49: aload         5
      51: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload         4
      60: aload         6
      62: checkcast     #61                 // class kotlin/collections/IndexedValue
      65: astore        7
      67: astore        8
      69: iconst_0
      70: istore        9
      72: aload         8
      74: invokevirtual #66                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
      77: checkcast     #68                 // class java/lang/Number
      80: invokevirtual #72                 // Method java/lang/Number.intValue:()I
      83: istore        10
      85: aload         8
      87: invokevirtual #75                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
      90: checkcast     #33                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/warmUpChallenges/clouds/PenaltyState
      93: astore        11
      95: aload         7
      97: invokevirtual #77                 // Method kotlin/collections/IndexedValue.component1:()I
     100: istore        12
     102: aload         7
     104: invokevirtual #78                 // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     107: checkcast     #68                 // class java/lang/Number
     110: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     113: istore        13
     115: iload         13
     117: invokestatic  #82                 // Method jumpingOnClouds$isThunder:(I)Z
     120: ifeq          151
     123: aload         11
     125: iload         12
     127: invokevirtual #85                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/warmUpChallenges/clouds/PenaltyState.isApplicable:(I)Z
     130: ifeq          151
     133: iload         10
     135: iconst_1
     136: iadd
     137: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     140: aload         11
     142: invokevirtual #89                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/warmUpChallenges/clouds/PenaltyState.flip:()Lru/amai/study/hackerrank/practice/interviewPreparationKit/warmUpChallenges/clouds/PenaltyState;
     145: invokestatic  #43                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     148: goto          161
     151: iload         10
     153: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     156: aload         11
     158: invokestatic  #43                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     161: astore        4
     163: goto          39
     166: aload         4
     168: invokevirtual #66                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     171: checkcast     #68                 // class java/lang/Number
     174: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     177: istore_1
     178: aload_0
     179: arraylength
     180: iload_1
     181: iadd
     182: iconst_2
     183: idiv
     184: ireturn

  private static final void checkRequirement(java.lang.Integer[]);
    Code:
       0: aload_0
       1: astore_1
       2: iconst_0
       3: istore_2
       4: iconst_0
       5: istore_3
       6: aload_1
       7: arraylength
       8: istore        4
      10: iload_3
      11: iload         4
      13: if_icmpge     84
      16: aload_1
      17: iload_3
      18: aaload
      19: astore        5
      21: aload         5
      23: checkcast     #68                 // class java/lang/Number
      26: invokevirtual #72                 // Method java/lang/Number.intValue:()I
      29: istore        6
      31: iconst_0
      32: istore        7
      34: iconst_2
      35: anewarray     #27                 // class java/lang/Integer
      38: astore        8
      40: aload         8
      42: iconst_0
      43: iconst_0
      44: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: aastore
      48: aload         8
      50: iconst_1
      51: iconst_1
      52: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: aastore
      56: aload         8
      58: invokestatic  #111                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      61: iload         6
      63: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokeinterface #117,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
      71: ifne          78
      74: iconst_0
      75: goto          85
      78: iinc          3, 1
      81: goto          10
      84: iconst_1
      85: ifne          131
      88: iconst_0
      89: istore_2
      90: new           #119                // class java/lang/StringBuilder
      93: dup
      94: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
      97: ldc           #125                // String clouds must be numbered 0 or 1; got
      99: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     102: aload_0
     103: invokestatic  #135                // Method java/util/Arrays.toString:([Ljava/lang/Object;)Ljava/lang/String;
     106: dup
     107: ldc           #137                // String toString(...)
     109: invokestatic  #140                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     112: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     115: invokevirtual #143                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     118: astore_2
     119: new           #145                // class java/lang/IllegalArgumentException
     122: dup
     123: aload_2
     124: invokevirtual #146                // Method java/lang/Object.toString:()Ljava/lang/String;
     127: invokespecial #149                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     130: athrow
     131: aload_0
     132: arraylength
     133: istore_1
     134: iconst_2
     135: iload_1
     136: if_icmpgt     153
     139: iload_1
     140: bipush        101
     142: if_icmpge     149
     145: iconst_1
     146: goto          154
     149: iconst_0
     150: goto          154
     153: iconst_0
     154: ifne          192
     157: iconst_0
     158: istore_2
     159: new           #119                // class java/lang/StringBuilder
     162: dup
     163: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
     166: ldc           #151                // String number of clouds should be <= 100 and >= 2; got
     168: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     171: aload_0
     172: arraylength
     173: invokevirtual #154                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     176: invokevirtual #143                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     179: astore_2
     180: new           #145                // class java/lang/IllegalArgumentException
     183: dup
     184: aload_2
     185: invokevirtual #146                // Method java/lang/Object.toString:()Ljava/lang/String;
     188: invokespecial #149                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     191: athrow
     192: aload_0
     193: invokestatic  #158                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
     196: checkcast     #68                 // class java/lang/Number
     199: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     202: ifne          209
     205: iconst_1
     206: goto          210
     209: iconst_0
     210: ifne          256
     213: iconst_0
     214: istore_2
     215: new           #119                // class java/lang/StringBuilder
     218: dup
     219: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
     222: ldc           #160                // String first cloud should be 0; got
     224: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     227: aload_0
     228: invokestatic  #158                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
     231: checkcast     #68                 // class java/lang/Number
     234: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     237: invokevirtual #154                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     240: invokevirtual #143                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     243: astore_2
     244: new           #145                // class java/lang/IllegalArgumentException
     247: dup
     248: aload_2
     249: invokevirtual #146                // Method java/lang/Object.toString:()Ljava/lang/String;
     252: invokespecial #149                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     255: athrow
     256: aload_0
     257: invokestatic  #163                // Method kotlin/collections/ArraysKt.last:([Ljava/lang/Object;)Ljava/lang/Object;
     260: checkcast     #68                 // class java/lang/Number
     263: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     266: ifne          273
     269: iconst_1
     270: goto          274
     273: iconst_0
     274: ifne          320
     277: iconst_0
     278: istore_2
     279: new           #119                // class java/lang/StringBuilder
     282: dup
     283: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
     286: ldc           #165                // String last cloud should be 0; got
     288: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     291: aload_0
     292: invokestatic  #163                // Method kotlin/collections/ArraysKt.last:([Ljava/lang/Object;)Ljava/lang/Object;
     295: checkcast     #68                 // class java/lang/Number
     298: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     301: invokevirtual #154                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     304: invokevirtual #143                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     307: astore_2
     308: new           #145                // class java/lang/IllegalArgumentException
     311: dup
     312: aload_2
     313: invokevirtual #146                // Method java/lang/Object.toString:()Ljava/lang/String;
     316: invokespecial #149                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     319: athrow
     320: aload_0
     321: invokestatic  #168                // Method kotlin/collections/ArraysKt.toList:([Ljava/lang/Object;)Ljava/util/List;
     324: checkcast     #45                 // class java/lang/Iterable
     327: invokestatic  #172                // Method kotlin/collections/CollectionsKt.zipWithNext:(Ljava/lang/Iterable;)Ljava/util/List;
     330: checkcast     #45                 // class java/lang/Iterable
     333: astore_1
     334: nop
     335: iconst_0
     336: istore_2
     337: aload_1
     338: astore_3
     339: new           #174                // class java/util/ArrayList
     342: dup
     343: aload_1
     344: bipush        10
     346: invokestatic  #178                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     349: invokespecial #181                // Method java/util/ArrayList."<init>":(I)V
     352: checkcast     #183                // class java/util/Collection
     355: astore        4
     357: iconst_0
     358: istore        5
     360: aload_3
     361: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     366: astore        6
     368: aload         6
     370: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     375: ifeq          447
     378: aload         6
     380: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     385: astore        7
     387: aload         4
     389: aload         7
     391: checkcast     #63                 // class kotlin/Pair
     394: astore        8
     396: astore        12
     398: iconst_0
     399: istore        9
     401: aload         8
     403: invokevirtual #66                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     406: checkcast     #68                 // class java/lang/Number
     409: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     412: istore        10
     414: aload         8
     416: invokevirtual #75                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     419: checkcast     #68                 // class java/lang/Number
     422: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     425: istore        11
     427: iload         10
     429: iload         11
     431: iadd
     432: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     435: aload         12
     437: swap
     438: invokeinterface #186,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     443: pop
     444: goto          368
     447: aload         4
     449: checkcast     #113                // class java/util/List
     452: nop
     453: checkcast     #45                 // class java/lang/Iterable
     456: astore_1
     457: nop
     458: iconst_0
     459: istore_2
     460: aload_1
     461: instanceof    #183                // class java/util/Collection
     464: ifeq          483
     467: aload_1
     468: checkcast     #183                // class java/util/Collection
     471: invokeinterface #189,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     476: ifeq          483
     479: iconst_1
     480: goto          539
     483: aload_1
     484: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     489: astore_3
     490: aload_3
     491: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     496: ifeq          538
     499: aload_3
     500: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     505: astore        4
     507: aload         4
     509: checkcast     #68                 // class java/lang/Number
     512: invokevirtual #72                 // Method java/lang/Number.intValue:()I
     515: istore        5
     517: iconst_0
     518: istore        6
     520: iload         5
     522: iconst_2
     523: if_icmpeq     530
     526: iconst_1
     527: goto          531
     530: iconst_0
     531: ifne          490
     534: iconst_0
     535: goto          539
     538: iconst_1
     539: ifne          585
     542: iconst_0
     543: istore_2
     544: new           #119                // class java/lang/StringBuilder
     547: dup
     548: invokespecial #123                // Method java/lang/StringBuilder."<init>":()V
     551: ldc           #191                // String there should not be two consecutive 1\'s in clouds; got
     553: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     556: aload_0
     557: invokestatic  #135                // Method java/util/Arrays.toString:([Ljava/lang/Object;)Ljava/lang/String;
     560: dup
     561: ldc           #137                // String toString(...)
     563: invokestatic  #140                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     566: invokevirtual #129                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     569: invokevirtual #143                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     572: astore_2
     573: new           #145                // class java/lang/IllegalArgumentException
     576: dup
     577: aload_2
     578: invokevirtual #146                // Method java/lang/Object.toString:()Ljava/lang/String;
     581: invokespecial #149                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     584: athrow
     585: return

  public static final void main();
    Code:
       0: new           #214                // class java/util/Scanner
       3: dup
       4: getstatic     #220                // Field java/lang/System.in:Ljava/io/InputStream;
       7: invokespecial #223                // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      10: astore_0
      11: aload_0
      12: invokevirtual #226                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      15: dup
      16: ldc           #228                // String nextLine(...)
      18: invokestatic  #140                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: checkcast     #230                // class java/lang/CharSequence
      24: invokestatic  #236                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      27: invokevirtual #146                // Method java/lang/Object.toString:()Ljava/lang/String;
      30: pop
      31: aload_0
      32: invokevirtual #226                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      35: dup
      36: ldc           #228                // String nextLine(...)
      38: invokestatic  #140                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      41: checkcast     #230                // class java/lang/CharSequence
      44: iconst_1
      45: anewarray     #238                // class java/lang/String
      48: astore_2
      49: aload_2
      50: iconst_0
      51: ldc           #240                // String
      53: aastore
      54: aload_2
      55: iconst_0
      56: iconst_0
      57: bipush        6
      59: aconst_null
      60: invokestatic  #244                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      63: checkcast     #45                 // class java/lang/Iterable
      66: astore_2
      67: iconst_0
      68: istore_3
      69: aload_2
      70: astore        4
      72: new           #174                // class java/util/ArrayList
      75: dup
      76: aload_2
      77: bipush        10
      79: invokestatic  #178                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      82: invokespecial #181                // Method java/util/ArrayList."<init>":(I)V
      85: checkcast     #183                // class java/util/Collection
      88: astore        5
      90: iconst_0
      91: istore        6
      93: aload         4
      95: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     100: astore        7
     102: aload         7
     104: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     109: ifeq          166
     112: aload         7
     114: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     119: astore        8
     121: aload         5
     123: aload         8
     125: checkcast     #238                // class java/lang/String
     128: astore        9
     130: astore        11
     132: iconst_0
     133: istore        10
     135: nop
     136: aload         9
     138: checkcast     #230                // class java/lang/CharSequence
     141: invokestatic  #236                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     144: invokevirtual #146                // Method java/lang/Object.toString:()Ljava/lang/String;
     147: invokestatic  #248                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     150: nop
     151: invokestatic  #31                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: aload         11
     156: swap
     157: invokeinterface #186,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     162: pop
     163: goto          102
     166: aload         5
     168: checkcast     #113                // class java/util/List
     171: nop
     172: checkcast     #183                // class java/util/Collection
     175: astore_2
     176: nop
     177: iconst_0
     178: istore_3
     179: aload_2
     180: astore        4
     182: aload         4
     184: iconst_0
     185: anewarray     #27                 // class java/lang/Integer
     188: invokeinterface #252,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     193: checkcast     #105                // class "[Ljava/lang/Integer;"
     196: astore_1
     197: aload_1
     198: invokestatic  #254                // Method jumpingOnClouds:([Ljava/lang/Integer;)I
     201: istore_2
     202: getstatic     #258                // Field java/lang/System.out:Ljava/io/PrintStream;
     205: iload_2
     206: invokevirtual #263                // Method java/io/PrintStream.println:(I)V
     209: return

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

  private static final boolean jumpingOnClouds$isThunder(int);
    Code:
       0: iload_0
       1: iconst_1
       2: if_icmpne     9
       5: iconst_1
       6: goto          10
       9: iconst_0
      10: ireturn
}