package day17

import java.io.File
import kotlin.math.abs
import kotlin.math.round
import kotlin.math.sqrt

fun main() {
    val lines = File("src/main/kotlin/day17/input.txt").readLines()
    val (x1, x2) = lines.first().substringAfter("target area: x=").substringBefore(", y=").split("..")
        .map { it.toInt() }
    val (y1, y2) = lines.first().substringAfter("y=").split("..").map { it.toInt() }

    println(y1 * (y1 + 1) / 2)

    val maxSteps = abs(2*y1)

    val validSpeeds: MutableSet<Pair<Int, Int>> = mutableSetOf()
    for (steps in 1..maxSteps) {
        val minYSpeed = decrementalSpeed(y1, steps)
        val maxYSpeed = decrementalSpeed(y2, steps)
        val minXSpeed = decrementalSpeedWithFloor(x1, steps)
        val maxXSpeed = decrementalSpeedWithFloor(x2, steps)
        for (speedX in minXSpeed..maxXSpeed) {
            for (speedY in minYSpeed..maxYSpeed) {
                if (targetCoordinateY(speedY, steps) in y1..y2 && targetCoordinateX(speedX, steps) in x1..x2) {
                    validSpeeds.add(speedX to speedY)
                }
            }
        }
    }
    println(validSpeeds.size)
}

fun targetCoordinateX(speed: Int, steps: Int): Int {
    val coefficient = minOf(speed, steps)
    return coefficient * speed - (coefficient - 1) * coefficient / 2
}

fun targetCoordinateY(speed: Int, steps: Int): Int = steps * speed - (steps - 1) * steps / 2

fun decrementalSpeed(targetCoordinate: Int, steps: Int): Int = (targetCoordinate.toDouble() / steps + (steps - 1).toDouble() / 2).toInt()

fun decrementalSpeedWithFloor(targetCoordinate: Int, steps: Int): Int {
    val minXSpeedToReachCoordinate = minXSpeedToReach(targetCoordinate)
    val speed = decrementalSpeed(targetCoordinate, steps)
    return if (steps > minXSpeedToReachCoordinate) minXSpeedToReachCoordinate else speed
}

fun minXSpeedToReach(targetCoordinate: Int): Int = round(sqrt((targetCoordinate * 8 + 1).toDouble()) / 2 - 0.5).toInt()

Compiled from "solution.kt"
public final class day17.SolutionKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/main/kotlin/day17/input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      20: checkcast     #28                 // class java/lang/String
      23: ldc           #30                 // String target area: x=
      25: aconst_null
      26: iconst_2
      27: aconst_null
      28: invokestatic  #36                 // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      31: ldc           #38                 // String , y=
      33: aconst_null
      34: iconst_2
      35: aconst_null
      36: invokestatic  #41                 // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      39: checkcast     #43                 // class java/lang/CharSequence
      42: iconst_1
      43: anewarray     #28                 // class java/lang/String
      46: astore_2
      47: aload_2
      48: iconst_0
      49: ldc           #45                 // String ..
      51: aastore
      52: aload_2
      53: iconst_0
      54: iconst_0
      55: bipush        6
      57: aconst_null
      58: invokestatic  #49                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      61: checkcast     #51                 // class java/lang/Iterable
      64: astore_2
      65: nop
      66: iconst_0
      67: istore_3
      68: aload_2
      69: astore        4
      71: new           #53                 // class java/util/ArrayList
      74: dup
      75: aload_2
      76: bipush        10
      78: invokestatic  #57                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      81: invokespecial #60                 // Method java/util/ArrayList."<init>":(I)V
      84: checkcast     #62                 // class java/util/Collection
      87: astore        5
      89: iconst_0
      90: istore        6
      92: aload         4
      94: invokeinterface #66,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      99: astore        7
     101: aload         7
     103: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     108: ifeq          155
     111: aload         7
     113: invokeinterface #76,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     118: astore        8
     120: aload         5
     122: aload         8
     124: checkcast     #28                 // class java/lang/String
     127: astore        9
     129: astore        17
     131: iconst_0
     132: istore        10
     134: aload         9
     136: invokestatic  #82                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     139: nop
     140: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: aload         17
     145: swap
     146: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     151: pop
     152: goto          101
     155: aload         5
     157: checkcast     #92                 // class java/util/List
     160: nop
     161: astore_1
     162: aload_1
     163: iconst_0
     164: invokeinterface #96,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     169: checkcast     #98                 // class java/lang/Number
     172: invokevirtual #102                // Method java/lang/Number.intValue:()I
     175: istore_2
     176: aload_1
     177: iconst_1
     178: invokeinterface #96,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     183: checkcast     #98                 // class java/lang/Number
     186: invokevirtual #102                // Method java/lang/Number.intValue:()I
     189: istore_3
     190: aload_0
     191: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     194: checkcast     #28                 // class java/lang/String
     197: ldc           #104                // String y=
     199: aconst_null
     200: iconst_2
     201: aconst_null
     202: invokestatic  #36                 // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     205: checkcast     #43                 // class java/lang/CharSequence
     208: iconst_1
     209: anewarray     #28                 // class java/lang/String
     212: astore        5
     214: aload         5
     216: iconst_0
     217: ldc           #45                 // String ..
     219: aastore
     220: aload         5
     222: iconst_0
     223: iconst_0
     224: bipush        6
     226: aconst_null
     227: invokestatic  #49                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     230: checkcast     #51                 // class java/lang/Iterable
     233: astore        5
     235: iconst_0
     236: istore        6
     238: aload         5
     240: astore        7
     242: new           #53                 // class java/util/ArrayList
     245: dup
     246: aload         5
     248: bipush        10
     250: invokestatic  #57                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     253: invokespecial #60                 // Method java/util/ArrayList."<init>":(I)V
     256: checkcast     #62                 // class java/util/Collection
     259: astore        8
     261: iconst_0
     262: istore        9
     264: aload         7
     266: invokeinterface #66,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     271: astore        10
     273: aload         10
     275: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     280: ifeq          327
     283: aload         10
     285: invokeinterface #76,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     290: astore        11
     292: aload         8
     294: aload         11
     296: checkcast     #28                 // class java/lang/String
     299: astore        12
     301: astore        17
     303: iconst_0
     304: istore        13
     306: aload         12
     308: invokestatic  #82                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     311: nop
     312: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     315: aload         17
     317: swap
     318: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     323: pop
     324: goto          273
     327: aload         8
     329: checkcast     #92                 // class java/util/List
     332: nop
     333: astore        4
     335: aload         4
     337: iconst_0
     338: invokeinterface #96,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     343: checkcast     #98                 // class java/lang/Number
     346: invokevirtual #102                // Method java/lang/Number.intValue:()I
     349: istore        5
     351: aload         4
     353: iconst_1
     354: invokeinterface #96,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     359: checkcast     #98                 // class java/lang/Number
     362: invokevirtual #102                // Method java/lang/Number.intValue:()I
     365: istore        6
     367: iload         5
     369: iload         5
     371: iconst_1
     372: iadd
     373: imul
     374: iconst_2
     375: idiv
     376: istore        7
     378: getstatic     #110                // Field java/lang/System.out:Ljava/io/PrintStream;
     381: iload         7
     383: invokevirtual #115                // Method java/io/PrintStream.println:(I)V
     386: iconst_2
     387: iload         5
     389: imul
     390: invokestatic  #121                // Method java/lang/Math.abs:(I)I
     393: istore        7
     395: new           #123                // class java/util/LinkedHashSet
     398: dup
     399: invokespecial #125                // Method java/util/LinkedHashSet."<init>":()V
     402: checkcast     #127                // class java/util/Set
     405: astore        8
     407: iconst_1
     408: istore        9
     410: iload         9
     412: iload         7
     414: if_icmpgt     601
     417: iload         5
     419: iload         9
     421: invokestatic  #131                // Method decrementalSpeed:(II)I
     424: istore        10
     426: iload         6
     428: iload         9
     430: invokestatic  #131                // Method decrementalSpeed:(II)I
     433: istore        11
     435: iload_2
     436: iload         9
     438: invokestatic  #134                // Method decrementalSpeedWithFloor:(II)I
     441: istore        12
     443: iload_3
     444: iload         9
     446: invokestatic  #134                // Method decrementalSpeedWithFloor:(II)I
     449: istore        13
     451: iload         12
     453: istore        14
     455: iload         14
     457: iload         13
     459: if_icmpgt     588
     462: iload         10
     464: istore        15
     466: iload         15
     468: iload         11
     470: if_icmpgt     575
     473: iload         15
     475: iload         9
     477: invokestatic  #137                // Method targetCoordinateY:(II)I
     480: istore        16
     482: iload         5
     484: iload         16
     486: if_icmpgt     504
     489: iload         16
     491: iload         6
     493: if_icmpgt     500
     496: iconst_1
     497: goto          505
     500: iconst_0
     501: goto          505
     504: iconst_0
     505: ifeq          562
     508: iload         14
     510: iload         9
     512: invokestatic  #140                // Method targetCoordinateX:(II)I
     515: istore        16
     517: iload_2
     518: iload         16
     520: if_icmpgt     537
     523: iload         16
     525: iload_3
     526: if_icmpgt     533
     529: iconst_1
     530: goto          538
     533: iconst_0
     534: goto          538
     537: iconst_0
     538: ifeq          562
     541: aload         8
     543: iload         14
     545: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     548: iload         15
     550: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     553: invokestatic  #146                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     556: invokeinterface #147,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     561: pop
     562: iload         15
     564: iload         11
     566: if_icmpeq     575
     569: iinc          15, 1
     572: goto          473
     575: iload         14
     577: iload         13
     579: if_icmpeq     588
     582: iinc          14, 1
     585: goto          462
     588: iload         9
     590: iload         7
     592: if_icmpeq     601
     595: iinc          9, 1
     598: goto          417
     601: aload         8
     603: invokeinterface #150,  1          // InterfaceMethod java/util/Set.size:()I
     608: istore        9
     610: getstatic     #110                // Field java/lang/System.out:Ljava/io/PrintStream;
     613: iload         9
     615: invokevirtual #115                // Method java/io/PrintStream.println:(I)V
     618: return

  public static final int targetCoordinateX(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: invokestatic  #183                // Method java/lang/Math.min:(II)I
       5: istore_2
       6: iload_2
       7: iload_0
       8: imul
       9: iload_2
      10: iconst_1
      11: isub
      12: iload_2
      13: imul
      14: iconst_2
      15: idiv
      16: isub
      17: ireturn

  public static final int targetCoordinateY(int, int);
    Code:
       0: iload_1
       1: iload_0
       2: imul
       3: iload_1
       4: iconst_1
       5: isub
       6: iload_1
       7: imul
       8: iconst_2
       9: idiv
      10: isub
      11: ireturn

  public static final int decrementalSpeed(int, int);
    Code:
       0: iload_0
       1: i2d
       2: iload_1
       3: i2d
       4: ddiv
       5: iload_1
       6: iconst_1
       7: isub
       8: i2d
       9: iconst_2
      10: i2d
      11: ddiv
      12: dadd
      13: d2i
      14: ireturn

  public static final int decrementalSpeedWithFloor(int, int);
    Code:
       0: iload_0
       1: invokestatic  #189                // Method minXSpeedToReach:(I)I
       4: istore_2
       5: iload_0
       6: iload_1
       7: invokestatic  #131                // Method decrementalSpeed:(II)I
      10: istore_3
      11: iload_1
      12: iload_2
      13: if_icmple     20
      16: iload_2
      17: goto          21
      20: iload_3
      21: ireturn

  public static final int minXSpeedToReach(int);
    Code:
       0: iload_0
       1: bipush        8
       3: imul
       4: iconst_1
       5: iadd
       6: i2d
       7: invokestatic  #194                // Method java/lang/Math.sqrt:(D)D
      10: iconst_2
      11: i2d
      12: ddiv
      13: ldc2_w        #195                // double 0.5d
      16: dsub
      17: invokestatic  #199                // Method java/lang/Math.rint:(D)D
      20: d2i
      21: ireturn

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


package day21

fun main() {
    val player1 = Player(4)
    val player2 = Player(3)
    val die = DeterministicDie()
    var roundNumber = 0
    var losingPlayer: Player

    while (player1.score < 1000 && player2.score < 1000) {
        if (roundNumber % 2 == 0) {
            val score = die.roll() + die.roll() + die.roll()
            player1.addScore(score)
        } else {
            val score = die.roll() + die.roll() + die.roll()
            player2.addScore(score)
        }
        roundNumber++
    }
    losingPlayer = if (player1.score >= 1000) {
        player2
    } else {
        player1
    }
    println(losingPlayer.score * die.numberOfRolls)

    val thrownValueToNumberOfUniverses = mapOf<Int, Long>(
        3 to 1,
        4 to 3,
        5 to 6,
        6 to 7,
        7 to 6,
        8 to 3,
        9 to 1,
    )

    val (player1WonUniverses, player2WonUniverses) = thrownValueToNumberOfUniverses.keys
        .map {
            playRound(
                true,
                it,
                4,
                0,
                3,
                0,
                1,
                thrownValueToNumberOfUniverses
            )
        }
        .reduce { p1, p2 -> p1.first + p2.first to p1.second + p2.second }
    println(maxOf(player1WonUniverses, player2WonUniverses))
}

fun playRound(
    playsFirstPlayer: Boolean,
    thrownValue: Int,
    player1Position: Int,
    player1Score: Int,
    player2Position: Int,
    player2Score: Int,
    numberOfUniverses: Long,
    thrownValueToNumberOfUniverses: Map<Int, Long>
): Pair<Long, Long> {
        val newPlayer1Position: Int
        val newPlayer1Score: Int
        val newPlayer2Position: Int
        val newPlayer2Score: Int
        val newNumberOfUniverses: Long
        if (playsFirstPlayer) {
            newPlayer1Position = (player1Position + thrownValue - 1) % 10 + 1
            newPlayer1Score = player1Score + newPlayer1Position
            newNumberOfUniverses = numberOfUniverses * thrownValueToNumberOfUniverses.getValue(thrownValue)
            newPlayer2Position = player2Position
            newPlayer2Score = player2Score
            if (newPlayer1Score >= 21) return newNumberOfUniverses to 0L
        } else {
            newPlayer2Position = (player2Position + thrownValue - 1) % 10 + 1
            newPlayer2Score = player2Score + newPlayer2Position
            newNumberOfUniverses = numberOfUniverses * thrownValueToNumberOfUniverses.getValue(thrownValue)
            newPlayer1Position = player1Position
            newPlayer1Score = player1Score
            if (newPlayer2Score >= 21) return 0L to newNumberOfUniverses
        }
        return thrownValueToNumberOfUniverses.keys
            .map {
                playRound(
                    !playsFirstPlayer,
                    it,
                    newPlayer1Position,
                    newPlayer1Score,
                    newPlayer2Position,
                    newPlayer2Score,
                    newNumberOfUniverses,
                    thrownValueToNumberOfUniverses
                )
            }
            .reduce { p1, p2 -> p1.first + p2.first to p1.second + p2.second}
}

data class Player(var position: Int) {
    var score: Int = 0
    fun addScore(value: Int) {
        position = (position + value - 1) % 10 + 1
        score += position
    }
}

data class DeterministicDie(var currentValue: Int = 0) {
    var numberOfRolls: Int = 0
    fun roll(): Int {
        numberOfRolls++
        return (++currentValue - 1) % 100 + 1
    }
}

Compiled from "solution.kt"
public final class day21.SolutionKt {
  public static final void main();
    Code:
       0: new           #8                  // class day21/Player
       3: dup
       4: iconst_4
       5: invokespecial #12                 // Method day21/Player."<init>":(I)V
       8: astore_0
       9: new           #8                  // class day21/Player
      12: dup
      13: iconst_3
      14: invokespecial #12                 // Method day21/Player."<init>":(I)V
      17: astore_1
      18: new           #14                 // class day21/DeterministicDie
      21: dup
      22: iconst_0
      23: iconst_1
      24: aconst_null
      25: invokespecial #17                 // Method day21/DeterministicDie."<init>":(IILkotlin/jvm/internal/DefaultConstructorMarker;)V
      28: astore_2
      29: iconst_0
      30: istore_3
      31: aconst_null
      32: astore        4
      34: aload_0
      35: invokevirtual #21                 // Method day21/Player.getScore:()I
      38: sipush        1000
      41: if_icmpge     113
      44: aload_1
      45: invokevirtual #21                 // Method day21/Player.getScore:()I
      48: sipush        1000
      51: if_icmpge     113
      54: iload_3
      55: iconst_2
      56: irem
      57: ifne          85
      60: aload_2
      61: invokevirtual #24                 // Method day21/DeterministicDie.roll:()I
      64: aload_2
      65: invokevirtual #24                 // Method day21/DeterministicDie.roll:()I
      68: iadd
      69: aload_2
      70: invokevirtual #24                 // Method day21/DeterministicDie.roll:()I
      73: iadd
      74: istore        5
      76: aload_0
      77: iload         5
      79: invokevirtual #27                 // Method day21/Player.addScore:(I)V
      82: goto          107
      85: aload_2
      86: invokevirtual #24                 // Method day21/DeterministicDie.roll:()I
      89: aload_2
      90: invokevirtual #24                 // Method day21/DeterministicDie.roll:()I
      93: iadd
      94: aload_2
      95: invokevirtual #24                 // Method day21/DeterministicDie.roll:()I
      98: iadd
      99: istore        5
     101: aload_1
     102: iload         5
     104: invokevirtual #27                 // Method day21/Player.addScore:(I)V
     107: iinc          3, 1
     110: goto          34
     113: aload_0
     114: invokevirtual #21                 // Method day21/Player.getScore:()I
     117: sipush        1000
     120: if_icmplt     127
     123: aload_1
     124: goto          128
     127: aload_0
     128: astore        4
     130: aload         4
     132: invokevirtual #21                 // Method day21/Player.getScore:()I
     135: aload_2
     136: invokevirtual #30                 // Method day21/DeterministicDie.getNumberOfRolls:()I
     139: imul
     140: istore        5
     142: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
     145: iload         5
     147: invokevirtual #41                 // Method java/io/PrintStream.println:(I)V
     150: bipush        7
     152: anewarray     #43                 // class kotlin/Pair
     155: astore        6
     157: aload         6
     159: iconst_0
     160: iconst_3
     161: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     164: lconst_1
     165: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     168: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     171: aastore
     172: aload         6
     174: iconst_1
     175: iconst_4
     176: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     179: ldc2_w        #61                 // long 3l
     182: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     185: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     188: aastore
     189: aload         6
     191: iconst_2
     192: iconst_5
     193: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     196: ldc2_w        #63                 // long 6l
     199: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     202: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     205: aastore
     206: aload         6
     208: iconst_3
     209: bipush        6
     211: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     214: ldc2_w        #65                 // long 7l
     217: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     220: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     223: aastore
     224: aload         6
     226: iconst_4
     227: bipush        7
     229: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     232: ldc2_w        #63                 // long 6l
     235: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     238: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     241: aastore
     242: aload         6
     244: iconst_5
     245: bipush        8
     247: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     250: ldc2_w        #61                 // long 3l
     253: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     256: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     259: aastore
     260: aload         6
     262: bipush        6
     264: bipush        9
     266: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     269: lconst_1
     270: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     273: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     276: aastore
     277: aload         6
     279: invokestatic  #72                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     282: astore        5
     284: aload         5
     286: invokeinterface #78,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     291: checkcast     #80                 // class java/lang/Iterable
     294: astore        7
     296: nop
     297: iconst_0
     298: istore        8
     300: aload         7
     302: astore        9
     304: new           #82                 // class java/util/ArrayList
     307: dup
     308: aload         7
     310: bipush        10
     312: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     315: invokespecial #89                 // Method java/util/ArrayList."<init>":(I)V
     318: checkcast     #91                 // class java/util/Collection
     321: astore        10
     323: iconst_0
     324: istore        11
     326: aload         9
     328: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     333: astore        12
     335: aload         12
     337: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     342: ifeq          397
     345: aload         12
     347: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     352: astore        13
     354: aload         10
     356: aload         13
     358: checkcast     #107                // class java/lang/Number
     361: invokevirtual #110                // Method java/lang/Number.intValue:()I
     364: istore        14
     366: astore        16
     368: iconst_0
     369: istore        15
     371: iconst_1
     372: iload         14
     374: iconst_4
     375: iconst_0
     376: iconst_3
     377: iconst_0
     378: lconst_1
     379: aload         5
     381: invokestatic  #114                // Method playRound:(ZIIIIIJLjava/util/Map;)Lkotlin/Pair;
     384: nop
     385: aload         16
     387: swap
     388: invokeinterface #118,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     393: pop
     394: goto          335
     397: aload         10
     399: checkcast     #120                // class java/util/List
     402: nop
     403: checkcast     #80                 // class java/lang/Iterable
     406: astore        7
     408: nop
     409: iconst_0
     410: istore        8
     412: aload         7
     414: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     419: astore        9
     421: aload         9
     423: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     428: ifne          441
     431: new           #122                // class java/lang/UnsupportedOperationException
     434: dup
     435: ldc           #124                // String Empty collection can\'t be reduced.
     437: invokespecial #127                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     440: athrow
     441: aload         9
     443: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     448: astore        10
     450: aload         9
     452: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     457: ifeq          542
     460: aload         10
     462: aload         9
     464: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     469: checkcast     #43                 // class kotlin/Pair
     472: astore        11
     474: checkcast     #43                 // class kotlin/Pair
     477: astore        12
     479: iconst_0
     480: istore        13
     482: aload         12
     484: invokevirtual #130                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     487: checkcast     #107                // class java/lang/Number
     490: invokevirtual #134                // Method java/lang/Number.longValue:()J
     493: aload         11
     495: invokevirtual #130                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     498: checkcast     #107                // class java/lang/Number
     501: invokevirtual #134                // Method java/lang/Number.longValue:()J
     504: ladd
     505: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     508: aload         12
     510: invokevirtual #137                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     513: checkcast     #107                // class java/lang/Number
     516: invokevirtual #134                // Method java/lang/Number.longValue:()J
     519: aload         11
     521: invokevirtual #137                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     524: checkcast     #107                // class java/lang/Number
     527: invokevirtual #134                // Method java/lang/Number.longValue:()J
     530: ladd
     531: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     534: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     537: astore        10
     539: goto          450
     542: aload         10
     544: checkcast     #43                 // class kotlin/Pair
     547: astore        6
     549: aload         6
     551: invokevirtual #140                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     554: checkcast     #107                // class java/lang/Number
     557: invokevirtual #134                // Method java/lang/Number.longValue:()J
     560: lstore        7
     562: aload         6
     564: invokevirtual #143                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     567: checkcast     #107                // class java/lang/Number
     570: invokevirtual #134                // Method java/lang/Number.longValue:()J
     573: lstore        9
     575: lload         7
     577: lload         9
     579: invokestatic  #149                // Method java/lang/Math.max:(JJ)J
     582: lstore        11
     584: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
     587: lload         11
     589: invokevirtual #152                // Method java/io/PrintStream.println:(J)V
     592: return

  public static final kotlin.Pair<java.lang.Long, java.lang.Long> playRound(boolean, int, int, int, int, int, long, java.util.Map<java.lang.Integer, java.lang.Long>);
    Code:
       0: aload         8
       2: ldc           #191                // String thrownValueToNumberOfUniverses
       4: invokestatic  #197                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: iconst_0
       8: istore        9
      10: iconst_0
      11: istore        10
      13: iconst_0
      14: istore        11
      16: iconst_0
      17: istore        12
      19: lconst_0
      20: lstore        13
      22: iload_0
      23: ifeq          92
      26: iload_2
      27: iload_1
      28: iadd
      29: iconst_1
      30: isub
      31: bipush        10
      33: irem
      34: iconst_1
      35: iadd
      36: istore        9
      38: iload_3
      39: iload         9
      41: iadd
      42: istore        10
      44: lload         6
      46: aload         8
      48: iload_1
      49: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: invokestatic  #201                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      55: checkcast     #107                // class java/lang/Number
      58: invokevirtual #134                // Method java/lang/Number.longValue:()J
      61: lmul
      62: lstore        13
      64: iload         4
      66: istore        11
      68: iload         5
      70: istore        12
      72: iload         10
      74: bipush        21
      76: if_icmplt     158
      79: lload         13
      81: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      84: lconst_0
      85: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      88: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      91: areturn
      92: iload         4
      94: iload_1
      95: iadd
      96: iconst_1
      97: isub
      98: bipush        10
     100: irem
     101: iconst_1
     102: iadd
     103: istore        11
     105: iload         5
     107: iload         11
     109: iadd
     110: istore        12
     112: lload         6
     114: aload         8
     116: iload_1
     117: invokestatic  #49                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: invokestatic  #201                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     123: checkcast     #107                // class java/lang/Number
     126: invokevirtual #134                // Method java/lang/Number.longValue:()J
     129: lmul
     130: lstore        13
     132: iload_2
     133: istore        9
     135: iload_3
     136: istore        10
     138: iload         12
     140: bipush        21
     142: if_icmplt     158
     145: lconst_0
     146: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     149: lload         13
     151: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     154: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     157: areturn
     158: aload         8
     160: invokeinterface #78,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     165: checkcast     #80                 // class java/lang/Iterable
     168: astore        15
     170: nop
     171: iconst_0
     172: istore        16
     174: aload         15
     176: astore        17
     178: new           #82                 // class java/util/ArrayList
     181: dup
     182: aload         15
     184: bipush        10
     186: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     189: invokespecial #89                 // Method java/util/ArrayList."<init>":(I)V
     192: checkcast     #91                 // class java/util/Collection
     195: astore        18
     197: iconst_0
     198: istore        19
     200: aload         17
     202: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     207: astore        20
     209: aload         20
     211: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     216: ifeq          284
     219: aload         20
     221: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     226: astore        21
     228: aload         18
     230: aload         21
     232: checkcast     #107                // class java/lang/Number
     235: invokevirtual #110                // Method java/lang/Number.intValue:()I
     238: istore        22
     240: astore        24
     242: iconst_0
     243: istore        23
     245: iload_0
     246: ifne          253
     249: iconst_1
     250: goto          254
     253: iconst_0
     254: iload         22
     256: iload         9
     258: iload         10
     260: iload         11
     262: iload         12
     264: lload         13
     266: aload         8
     268: invokestatic  #114                // Method playRound:(ZIIIIIJLjava/util/Map;)Lkotlin/Pair;
     271: nop
     272: aload         24
     274: swap
     275: invokeinterface #118,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     280: pop
     281: goto          209
     284: aload         18
     286: checkcast     #120                // class java/util/List
     289: nop
     290: checkcast     #80                 // class java/lang/Iterable
     293: astore        15
     295: nop
     296: iconst_0
     297: istore        16
     299: aload         15
     301: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     306: astore        17
     308: aload         17
     310: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     315: ifne          328
     318: new           #122                // class java/lang/UnsupportedOperationException
     321: dup
     322: ldc           #124                // String Empty collection can\'t be reduced.
     324: invokespecial #127                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     327: athrow
     328: aload         17
     330: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     335: astore        18
     337: aload         17
     339: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     344: ifeq          429
     347: aload         18
     349: aload         17
     351: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     356: checkcast     #43                 // class kotlin/Pair
     359: astore        19
     361: checkcast     #43                 // class kotlin/Pair
     364: astore        20
     366: iconst_0
     367: istore        21
     369: aload         20
     371: invokevirtual #130                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     374: checkcast     #107                // class java/lang/Number
     377: invokevirtual #134                // Method java/lang/Number.longValue:()J
     380: aload         19
     382: invokevirtual #130                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     385: checkcast     #107                // class java/lang/Number
     388: invokevirtual #134                // Method java/lang/Number.longValue:()J
     391: ladd
     392: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     395: aload         20
     397: invokevirtual #137                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     400: checkcast     #107                // class java/lang/Number
     403: invokevirtual #134                // Method java/lang/Number.longValue:()J
     406: aload         19
     408: invokevirtual #137                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     411: checkcast     #107                // class java/lang/Number
     414: invokevirtual #134                // Method java/lang/Number.longValue:()J
     417: ladd
     418: invokestatic  #54                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     421: invokestatic  #60                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     424: astore        18
     426: goto          337
     429: aload         18
     431: checkcast     #43                 // class kotlin/Pair
     434: areturn

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