import java.lang.RuntimeException

fun main() {
    RPS.solve()
}

private object RPS {
    // Day 2
    fun solve() {
        val input = readInput()
        var result = 0
        for (pair in input) {
            val myMove = when(pair.second) {
                Result.Draw -> pair.first
                Result.Win -> when(pair.first) {
                    Move.Rock -> Move.Paper
                    Move.Paper -> Move.Scissors
                    Move.Scissors -> Move.Rock
                }
                Result.Lose -> when(pair.first) {
                    Move.Rock -> Move.Scissors
                    Move.Paper -> Move.Rock
                    Move.Scissors -> Move.Paper
                }
            }
            val game = Pair(pair.first, myMove)
            result += getScore(game)
        }
        println("Total score: $result")
    }

    private fun readInput(): Iterable<Pair<Move, Result>> {
        val result = mutableListOf<Pair<Move, Result>>()
        val lines = generateSequence(::readLine)
        for (line in lines) {
            val parts = line.split(" ")
            val first = when (parts[0]) {
                "A" -> Move.Rock
                "B" -> Move.Paper
                "C" -> Move.Scissors
                else -> throw RuntimeException("Invalid first char")
            }
            val second = when (parts[1]) {
                "X" -> Result.Lose
                "Y" -> Result.Draw
                "Z" -> Result.Win
                else -> throw RuntimeException("Invalid second char")
            }
            result.add(Pair(first, second))
        }
        return result
    }

    private fun getScore(game: Pair<Move, Move>): Int {
        val my = game.second
        val other = game.first
        var score = when (my) {
            Move.Rock -> 1
            Move.Paper -> 2
            Move.Scissors -> 3
        }
        score += when {
            my == other -> 3
            my == Move.Rock && other == Move.Scissors -> 6
            my == Move.Paper && other == Move.Rock -> 6
            my == Move.Scissors && other == Move.Paper -> 6
            else -> 0
        }
        return score
    }

    private enum class Move {
        Rock,
        Paper,
        Scissors
    }

    private enum class Result {
        Lose,
        Draw,
        Win
    }
}

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

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

  public final void solve();
    Code:
       0: aload_0
       1: invokespecial #15                 // Method readInput:()Ljava/lang/Iterable;
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: invokeinterface #21,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      13: astore_3
      14: aload_3
      15: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      20: ifeq          260
      23: aload_3
      24: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      29: checkcast     #33                 // class kotlin/Pair
      32: astore        4
      34: aload         4
      36: invokevirtual #36                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      39: checkcast     #38                 // class RPS$Result
      42: getstatic     #44                 // Field RPS$WhenMappings.$EnumSwitchMapping$1:[I
      45: swap
      46: invokevirtual #48                 // Method RPS$Result.ordinal:()I
      49: iaload
      50: tableswitch   { // 1 to 3
                     1: 76
                     2: 87
                     3: 154
               default: 222
          }
      76: aload         4
      78: invokevirtual #51                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      81: checkcast     #53                 // class RPS$Move
      84: goto          230
      87: aload         4
      89: invokevirtual #51                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      92: checkcast     #53                 // class RPS$Move
      95: getstatic     #56                 // Field RPS$WhenMappings.$EnumSwitchMapping$0:[I
      98: swap
      99: invokevirtual #57                 // Method RPS$Move.ordinal:()I
     102: iaload
     103: tableswitch   { // 1 to 3
                     1: 128
                     2: 134
                     3: 140
               default: 146
          }
     128: getstatic     #61                 // Field RPS$Move.Paper:LRPS$Move;
     131: goto          230
     134: getstatic     #64                 // Field RPS$Move.Scissors:LRPS$Move;
     137: goto          230
     140: getstatic     #67                 // Field RPS$Move.Rock:LRPS$Move;
     143: goto          230
     146: new           #69                 // class kotlin/NoWhenBranchMatchedException
     149: dup
     150: invokespecial #70                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     153: athrow
     154: aload         4
     156: invokevirtual #51                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     159: checkcast     #53                 // class RPS$Move
     162: getstatic     #56                 // Field RPS$WhenMappings.$EnumSwitchMapping$0:[I
     165: swap
     166: invokevirtual #57                 // Method RPS$Move.ordinal:()I
     169: iaload
     170: tableswitch   { // 1 to 3
                     1: 196
                     2: 202
                     3: 208
               default: 214
          }
     196: getstatic     #64                 // Field RPS$Move.Scissors:LRPS$Move;
     199: goto          230
     202: getstatic     #67                 // Field RPS$Move.Rock:LRPS$Move;
     205: goto          230
     208: getstatic     #61                 // Field RPS$Move.Paper:LRPS$Move;
     211: goto          230
     214: new           #69                 // class kotlin/NoWhenBranchMatchedException
     217: dup
     218: invokespecial #70                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     221: athrow
     222: new           #69                 // class kotlin/NoWhenBranchMatchedException
     225: dup
     226: invokespecial #70                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     229: athrow
     230: astore        5
     232: new           #33                 // class kotlin/Pair
     235: dup
     236: aload         4
     238: invokevirtual #51                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     241: aload         5
     243: invokespecial #73                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     246: astore        6
     248: iload_2
     249: aload_0
     250: aload         6
     252: invokespecial #77                 // Method getScore:(Lkotlin/Pair;)I
     255: iadd
     256: istore_2
     257: goto          14
     260: new           #79                 // class java/lang/StringBuilder
     263: dup
     264: invokespecial #80                 // Method java/lang/StringBuilder."<init>":()V
     267: ldc           #82                 // String Total score:
     269: invokevirtual #86                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     272: iload_2
     273: invokevirtual #89                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     276: invokevirtual #93                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     279: getstatic     #99                 // Field java/lang/System.out:Ljava/io/PrintStream;
     282: swap
     283: invokevirtual #105                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     286: return

  private final java.lang.Iterable<kotlin.Pair<RPS$Move, RPS$Result>> readInput();
    Code:
       0: new           #116                // class java/util/ArrayList
       3: dup
       4: invokespecial #117                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #119                // class java/util/List
      10: astore_1
      11: getstatic     #125                // Field RPS$readInput$lines$1.INSTANCE:LRPS$readInput$lines$1;
      14: checkcast     #127                // class kotlin/jvm/functions/Function0
      17: invokestatic  #133                // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
      20: astore_2
      21: aload_2
      22: invokeinterface #136,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      27: astore_3
      28: aload_3
      29: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          322
      37: aload_3
      38: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      43: checkcast     #138                // class java/lang/String
      46: astore        4
      48: aload         4
      50: checkcast     #140                // class java/lang/CharSequence
      53: iconst_1
      54: anewarray     #138                // class java/lang/String
      57: astore        6
      59: aload         6
      61: iconst_0
      62: ldc           #142                // String
      64: aastore
      65: aload         6
      67: iconst_0
      68: iconst_0
      69: bipush        6
      71: aconst_null
      72: invokestatic  #148                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      75: astore        5
      77: aload         5
      79: iconst_0
      80: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      85: checkcast     #138                // class java/lang/String
      88: astore        7
      90: aload         7
      92: invokevirtual #155                // Method java/lang/String.hashCode:()I
      95: tableswitch   { // 65 to 67
                    65: 120
                    66: 133
                    67: 146
               default: 177
          }
     120: aload         7
     122: ldc           #157                // String A
     124: invokevirtual #161                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     127: ifne          159
     130: goto          177
     133: aload         7
     135: ldc           #163                // String B
     137: invokevirtual #161                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     140: ifne          165
     143: goto          177
     146: aload         7
     148: ldc           #165                // String C
     150: invokevirtual #161                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     153: ifne          171
     156: goto          177
     159: getstatic     #67                 // Field RPS$Move.Rock:LRPS$Move;
     162: goto          187
     165: getstatic     #61                 // Field RPS$Move.Paper:LRPS$Move;
     168: goto          187
     171: getstatic     #64                 // Field RPS$Move.Scissors:LRPS$Move;
     174: goto          187
     177: new           #167                // class java/lang/RuntimeException
     180: dup
     181: ldc           #169                // String Invalid first char
     183: invokespecial #172                // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
     186: athrow
     187: astore        6
     189: aload         5
     191: iconst_1
     192: invokeinterface #152,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     197: checkcast     #138                // class java/lang/String
     200: astore        8
     202: aload         8
     204: invokevirtual #155                // Method java/lang/String.hashCode:()I
     207: tableswitch   { // 88 to 90
                    88: 232
                    89: 245
                    90: 258
               default: 289
          }
     232: aload         8
     234: ldc           #174                // String X
     236: invokevirtual #161                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     239: ifne          271
     242: goto          289
     245: aload         8
     247: ldc           #176                // String Y
     249: invokevirtual #161                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     252: ifne          277
     255: goto          289
     258: aload         8
     260: ldc           #178                // String Z
     262: invokevirtual #161                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     265: ifne          283
     268: goto          289
     271: getstatic     #182                // Field RPS$Result.Lose:LRPS$Result;
     274: goto          299
     277: getstatic     #185                // Field RPS$Result.Draw:LRPS$Result;
     280: goto          299
     283: getstatic     #188                // Field RPS$Result.Win:LRPS$Result;
     286: goto          299
     289: new           #167                // class java/lang/RuntimeException
     292: dup
     293: ldc           #190                // String Invalid second char
     295: invokespecial #172                // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
     298: athrow
     299: astore        7
     301: aload_1
     302: new           #33                 // class kotlin/Pair
     305: dup
     306: aload         6
     308: aload         7
     310: invokespecial #73                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     313: invokeinterface #193,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     318: pop
     319: goto          28
     322: aload_1
     323: checkcast     #17                 // class java/lang/Iterable
     326: areturn

  private final int getScore(kotlin.Pair<? extends RPS$Move, ? extends RPS$Move>);
    Code:
       0: aload_1
       1: invokevirtual #36                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
       4: checkcast     #53                 // class RPS$Move
       7: astore_2
       8: aload_1
       9: invokevirtual #51                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      12: checkcast     #53                 // class RPS$Move
      15: astore_3
      16: aload_2
      17: getstatic     #56                 // Field RPS$WhenMappings.$EnumSwitchMapping$0:[I
      20: swap
      21: invokevirtual #57                 // Method RPS$Move.ordinal:()I
      24: iaload
      25: tableswitch   { // 1 to 3
                     1: 52
                     2: 56
                     3: 60
               default: 64
          }
      52: iconst_1
      53: goto          72
      56: iconst_2
      57: goto          72
      60: iconst_3
      61: goto          72
      64: new           #69                 // class kotlin/NoWhenBranchMatchedException
      67: dup
      68: invokespecial #70                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
      71: athrow
      72: istore        4
      74: iload         4
      76: aload_2
      77: aload_3
      78: if_acmpne     85
      81: iconst_3
      82: goto          143
      85: aload_2
      86: getstatic     #67                 // Field RPS$Move.Rock:LRPS$Move;
      89: if_acmpne     104
      92: aload_3
      93: getstatic     #64                 // Field RPS$Move.Scissors:LRPS$Move;
      96: if_acmpne     104
      99: bipush        6
     101: goto          143
     104: aload_2
     105: getstatic     #61                 // Field RPS$Move.Paper:LRPS$Move;
     108: if_acmpne     123
     111: aload_3
     112: getstatic     #67                 // Field RPS$Move.Rock:LRPS$Move;
     115: if_acmpne     123
     118: bipush        6
     120: goto          143
     123: aload_2
     124: getstatic     #64                 // Field RPS$Move.Scissors:LRPS$Move;
     127: if_acmpne     142
     130: aload_3
     131: getstatic     #61                 // Field RPS$Move.Paper:LRPS$Move;
     134: if_acmpne     142
     137: bipush        6
     139: goto          143
     142: iconst_0
     143: iadd
     144: istore        4
     146: iload         4
     148: ireturn

  static {};
    Code:
       0: new           #2                  // class RPS
       3: dup
       4: invokespecial #209                // Method "<init>":()V
       7: putstatic     #211                // Field INSTANCE:LRPS;
      10: return
}

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

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

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

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

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

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

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

Compiled from "RPS.kt"
public final class RPS$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  public static final int[] $EnumSwitchMapping$1;

  static {};
    Code:
       0: invokestatic  #14                 // Method RPS$Move.values:()[LRPS$Move;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field RPS$Move.Rock:LRPS$Move;
      12: invokevirtual #22                 // Method RPS$Move.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field RPS$Move.Paper:LRPS$Move;
      26: invokevirtual #22                 // Method RPS$Move.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field RPS$Move.Scissors:LRPS$Move;
      40: invokevirtual #22                 // Method RPS$Move.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: aload_0
      50: putstatic     #32                 // Field $EnumSwitchMapping$0:[I
      53: invokestatic  #37                 // Method RPS$Result.values:()[LRPS$Result;
      56: arraylength
      57: newarray       int
      59: astore_0
      60: nop
      61: aload_0
      62: getstatic     #41                 // Field RPS$Result.Draw:LRPS$Result;
      65: invokevirtual #42                 // Method RPS$Result.ordinal:()I
      68: iconst_1
      69: iastore
      70: goto          74
      73: astore_1
      74: nop
      75: aload_0
      76: getstatic     #45                 // Field RPS$Result.Win:LRPS$Result;
      79: invokevirtual #42                 // Method RPS$Result.ordinal:()I
      82: iconst_2
      83: iastore
      84: goto          88
      87: astore_1
      88: nop
      89: aload_0
      90: getstatic     #48                 // Field RPS$Result.Lose:LRPS$Result;
      93: invokevirtual #42                 // Method RPS$Result.ordinal:()I
      96: iconst_3
      97: iastore
      98: goto          102
     101: astore_1
     102: aload_0
     103: putstatic     #51                 // Field $EnumSwitchMapping$1:[I
     106: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
          60    70    73   Class java/lang/NoSuchFieldError
          74    84    87   Class java/lang/NoSuchFieldError
          88    98   101   Class java/lang/NoSuchFieldError
}

Compiled from "RPS.kt"
final class RPS$Move extends java.lang.Enum<RPS$Move> {
  public static final RPS$Move Rock;

  public static final RPS$Move Paper;

  public static final RPS$Move Scissors;

  private static final RPS$Move[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private RPS$Move();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #10                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: return

  public static RPS$Move[] values();
    Code:
       0: getstatic     #22                 // Field $VALUES:[LRPS$Move;
       3: invokevirtual #28                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #29                 // class "[LRPS$Move;"
       9: areturn

  public static RPS$Move valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class RPS$Move
       2: aload_0
       3: invokestatic  #34                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class RPS$Move
       9: areturn

  public static kotlin.enums.EnumEntries<RPS$Move> getEntries();
    Code:
       0: getstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final RPS$Move[] $values();
    Code:
       0: iconst_3
       1: anewarray     #2                  // class RPS$Move
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #47                 // Field Rock:LRPS$Move;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #50                 // Field Paper:LRPS$Move;
      16: aastore
      17: aload_0
      18: iconst_2
      19: getstatic     #53                 // Field Scissors:LRPS$Move;
      22: aastore
      23: aload_0
      24: areturn

  static {};
    Code:
       0: new           #2                  // class RPS$Move
       3: dup
       4: ldc           #55                 // String Rock
       6: iconst_0
       7: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      10: putstatic     #47                 // Field Rock:LRPS$Move;
      13: new           #2                  // class RPS$Move
      16: dup
      17: ldc           #57                 // String Paper
      19: iconst_1
      20: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      23: putstatic     #50                 // Field Paper:LRPS$Move;
      26: new           #2                  // class RPS$Move
      29: dup
      30: ldc           #58                 // String Scissors
      32: iconst_2
      33: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      36: putstatic     #53                 // Field Scissors:LRPS$Move;
      39: invokestatic  #60                 // Method $values:()[LRPS$Move;
      42: putstatic     #22                 // Field $VALUES:[LRPS$Move;
      45: getstatic     #22                 // Field $VALUES:[LRPS$Move;
      48: checkcast     #62                 // class "[Ljava/lang/Enum;"
      51: invokestatic  #68                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      54: putstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      57: return
}

Compiled from "RPS.kt"
final class RPS$Result extends java.lang.Enum<RPS$Result> {
  public static final RPS$Result Lose;

  public static final RPS$Result Draw;

  public static final RPS$Result Win;

  private static final RPS$Result[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private RPS$Result();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #10                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: return

  public static RPS$Result[] values();
    Code:
       0: getstatic     #22                 // Field $VALUES:[LRPS$Result;
       3: invokevirtual #28                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #29                 // class "[LRPS$Result;"
       9: areturn

  public static RPS$Result valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class RPS$Result
       2: aload_0
       3: invokestatic  #34                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class RPS$Result
       9: areturn

  public static kotlin.enums.EnumEntries<RPS$Result> getEntries();
    Code:
       0: getstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final RPS$Result[] $values();
    Code:
       0: iconst_3
       1: anewarray     #2                  // class RPS$Result
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #47                 // Field Lose:LRPS$Result;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #50                 // Field Draw:LRPS$Result;
      16: aastore
      17: aload_0
      18: iconst_2
      19: getstatic     #53                 // Field Win:LRPS$Result;
      22: aastore
      23: aload_0
      24: areturn

  static {};
    Code:
       0: new           #2                  // class RPS$Result
       3: dup
       4: ldc           #55                 // String Lose
       6: iconst_0
       7: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      10: putstatic     #47                 // Field Lose:LRPS$Result;
      13: new           #2                  // class RPS$Result
      16: dup
      17: ldc           #57                 // String Draw
      19: iconst_1
      20: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      23: putstatic     #50                 // Field Draw:LRPS$Result;
      26: new           #2                  // class RPS$Result
      29: dup
      30: ldc           #58                 // String Win
      32: iconst_2
      33: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      36: putstatic     #53                 // Field Win:LRPS$Result;
      39: invokestatic  #60                 // Method $values:()[LRPS$Result;
      42: putstatic     #22                 // Field $VALUES:[LRPS$Result;
      45: getstatic     #22                 // Field $VALUES:[LRPS$Result;
      48: checkcast     #62                 // class "[Ljava/lang/Enum;"
      51: invokestatic  #68                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      54: putstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      57: return
}


import java.math.BigInteger

fun main() = Monkeys.solve()

object Monkeys {
    private var inspectedBy = mutableListOf<Int>()

    fun solve() {
        val input = readInput()
        for (monkey in input) {
            inspectedBy.add(monkey.id, 0)
        }
        for (turn in 1..10000) {
            runTurn(input)
//            println("After turn $turn, items by monkey ${input.map { it.items }}")
        }
        val inspected = inspectedBy.sorted().takeLast(2)
        println("Inspected: $inspected, score: ${inspected.first().toBigInteger() * inspected.last().toBigInteger()}")
    }

    private fun readInput(): List<Monkey> {
        var id = 0
        var items = mutableListOf<BigInteger>()
        var operation: Operation? = null
        var testDiv = 0
        var ifTrue = 0
        var ifFalse = 0
        val result = mutableListOf<Monkey>()

        fun addMonkey() {
            if (operation == null) {
                throw Error("Invalid input, no operation before empty line")
            } else {
                val test = Test(testDiv, ifTrue, ifFalse)
                result.add(id, Monkey(id, items, operation!!, test))
            }
        }

        generateSequence(::readLine).forEach {
            when {
                it.startsWith(monkeyPrefix) -> {
                    id = it.substringAfter(monkeyPrefix).substringBefore(":").toInt(10)
                    items = mutableListOf<BigInteger>()
                    testDiv = 0
                    ifTrue = 0
                    ifFalse = 0
                }
                it.startsWith(itemsPrefix) -> {
                    items = it.substringAfter(itemsPrefix).split(", ").map { it.toBigInteger(10) }.toMutableList()
                }
                it.startsWith(operationPrefix) -> {
                    operation = parseOperation(it)
                }
                it.startsWith(testPrefix) -> {
                    testDiv = it.substringAfter(testPrefix).toInt(10)
                }
                it.startsWith(ifTruePrefix) -> {
                    ifTrue = it.substringAfter(ifTruePrefix).toInt(10)
                }
                it.startsWith(ifFalsePrefix) -> {
                    ifFalse = it.substringAfter(ifFalsePrefix).toInt(10)
                }
                (it == "") -> {
                    addMonkey()
                }
            }
        }
        addMonkey()
        return result
    }

    private fun runTurn(input: List<Monkey>) {
        for (monkey in input) {
            runRound(input, monkey)
//            println("round ${monkey.id} ends")
        }
    }

    private fun runRound(input: List<Monkey>, monkey: Monkey) {
        val base = input.map { it.test.testDiv }.reduce {acc, x -> x * acc}.toBigInteger()
        for (item in monkey.items) {
            val worry = monkey.operation.exec(item).mod(base)
            inspectedBy[monkey.id] += 1
//            println("Item $item, worry after inspection $worry")
            val target = if (worry.mod(monkey.test.testDiv.toBigInteger()) == BigInteger.ZERO) {
                input[monkey.test.ifTrue]
            } else {
                input[monkey.test.ifFalse]
            }
            target.items.add(worry)
//            println("Passing to monkey ${target.id}")
        }
        monkey.items.clear()
    }
}

val monkeyPrefix = "Monkey "
val itemsPrefix = "  Starting items: "
val operationPrefix = "  Operation: new = "
val testPrefix = "  Test: divisible by "
val ifTruePrefix = "    If true: throw to monkey "
val ifFalsePrefix = "    If false: throw to monkey "

private data class Monkey(val id: Int, val items: MutableList<BigInteger>, val operation: Operation, val test: Test)

sealed interface OpInput
object Old : OpInput
data class Just(val value: BigInteger): OpInput

enum class Op {
    Plus,
    Mul
}

data class Operation(val a: OpInput, val b: OpInput, val op: Op) {
    fun exec(input: BigInteger): BigInteger {
        val x = when (a) {
            Old -> input
            is Just -> a.value
        }
        val y = when (b) {
            Old -> input
            is Just -> b.value
        }
        return when (op) {
            Op.Plus -> x + y
            Op.Mul -> x * y
        }
    }
}

private fun parseOperation(line: String): Operation {
    val match = "(\\w+) ([+*]) (\\w+)".toRegex().matchEntire(line.substringAfter(operationPrefix))
    val op = when (match!!.groupValues[2]) {
        "*" -> Op.Mul
        "+" -> Op.Plus
        else -> throw Error("Unexpected op")
    }
    val a = parseOpInput(match.groupValues[1])
    val b = parseOpInput(match.groupValues[3])
    return Operation(a, b, op)
}

private fun parseOpInput(string: String): OpInput = when (string) {
    "old" -> Old
    else -> Just(string.toBigInteger(10))
}

private data class Test(val testDiv: Int, val ifTrue: Int, val ifFalse: Int)

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

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

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

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

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

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

  private static java.util.List<java.lang.Integer> inspectedBy;

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

  public final void solve();
    Code:
       0: aload_0
       1: invokespecial #15                 // Method readInput:()Ljava/util/List;
       4: astore_1
       5: aload_1
       6: invokeinterface #21,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      11: astore_2
      12: aload_2
      13: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      18: ifeq          50
      21: aload_2
      22: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      27: checkcast     #33                 // class Monkey
      30: astore_3
      31: getstatic     #37                 // Field inspectedBy:Ljava/util/List;
      34: aload_3
      35: invokevirtual #41                 // Method Monkey.getId:()I
      38: iconst_0
      39: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      42: invokeinterface #51,  3           // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
      47: goto          12
      50: iconst_1
      51: istore_2
      52: iload_2
      53: sipush        10001
      56: if_icmpge     70
      59: aload_0
      60: aload_1
      61: invokespecial #55                 // Method runTurn:(Ljava/util/List;)V
      64: iinc          2, 1
      67: goto          52
      70: getstatic     #37                 // Field inspectedBy:Ljava/util/List;
      73: checkcast     #57                 // class java/lang/Iterable
      76: invokestatic  #63                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      79: iconst_2
      80: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.takeLast:(Ljava/util/List;I)Ljava/util/List;
      83: astore_2
      84: new           #69                 // class java/lang/StringBuilder
      87: dup
      88: invokespecial #70                 // Method java/lang/StringBuilder."<init>":()V
      91: ldc           #72                 // String Inspected:
      93: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      96: aload_2
      97: invokevirtual #79                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     100: ldc           #81                 // String , score:
     102: invokevirtual #76                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     105: aload_2
     106: invokestatic  #85                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     109: checkcast     #87                 // class java/lang/Number
     112: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     115: i2l
     116: invokestatic  #95                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     119: dup
     120: ldc           #97                 // String valueOf(...)
     122: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     125: aload_2
     126: invokestatic  #106                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     129: checkcast     #87                 // class java/lang/Number
     132: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     135: i2l
     136: invokestatic  #95                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     139: dup
     140: ldc           #97                 // String valueOf(...)
     142: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     145: invokevirtual #110                // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     148: dup
     149: ldc           #112                // String multiply(...)
     151: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     154: invokevirtual #79                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     157: invokevirtual #116                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     160: getstatic     #122                // Field java/lang/System.out:Ljava/io/PrintStream;
     163: swap
     164: invokevirtual #128                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     167: return

  private final java.util.List<Monkey> readInput();
    Code:
       0: new           #137                // class kotlin/jvm/internal/Ref$IntRef
       3: dup
       4: invokespecial #138                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
       7: astore_1
       8: new           #140                // class kotlin/jvm/internal/Ref$ObjectRef
      11: dup
      12: invokespecial #141                // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
      15: astore_2
      16: aload_2
      17: new           #143                // class java/util/ArrayList
      20: dup
      21: invokespecial #144                // Method java/util/ArrayList."<init>":()V
      24: checkcast     #17                 // class java/util/List
      27: putfield      #148                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      30: new           #140                // class kotlin/jvm/internal/Ref$ObjectRef
      33: dup
      34: invokespecial #141                // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
      37: astore_3
      38: new           #137                // class kotlin/jvm/internal/Ref$IntRef
      41: dup
      42: invokespecial #138                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      45: astore        4
      47: new           #137                // class kotlin/jvm/internal/Ref$IntRef
      50: dup
      51: invokespecial #138                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      54: astore        5
      56: new           #137                // class kotlin/jvm/internal/Ref$IntRef
      59: dup
      60: invokespecial #138                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      63: astore        6
      65: new           #143                // class java/util/ArrayList
      68: dup
      69: invokespecial #144                // Method java/util/ArrayList."<init>":()V
      72: checkcast     #17                 // class java/util/List
      75: astore        7
      77: getstatic     #154                // Field Monkeys$readInput$1.INSTANCE:LMonkeys$readInput$1;
      80: checkcast     #156                // class kotlin/jvm/functions/Function0
      83: invokestatic  #162                // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
      86: astore        8
      88: iconst_0
      89: istore        9
      91: aload         8
      93: invokeinterface #165,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      98: astore        10
     100: aload         10
     102: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     107: ifeq          565
     110: aload         10
     112: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     117: astore        11
     119: aload         11
     121: checkcast     #167                // class java/lang/String
     124: astore        12
     126: iconst_0
     127: istore        13
     129: nop
     130: aload         12
     132: invokestatic  #172                // Method MonkeysKt.getMonkeyPrefix:()Ljava/lang/String;
     135: iconst_0
     136: iconst_2
     137: aconst_null
     138: invokestatic  #178                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     141: ifeq          210
     144: aload_1
     145: aload         12
     147: invokestatic  #172                // Method MonkeysKt.getMonkeyPrefix:()Ljava/lang/String;
     150: aconst_null
     151: iconst_2
     152: aconst_null
     153: invokestatic  #182                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     156: ldc           #184                // String :
     158: aconst_null
     159: iconst_2
     160: aconst_null
     161: invokestatic  #187                // Method kotlin/text/StringsKt.substringBefore$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     164: bipush        10
     166: invokestatic  #193                // Method kotlin/text/CharsKt.checkRadix:(I)I
     169: invokestatic  #197                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     172: putfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     175: aload_2
     176: new           #143                // class java/util/ArrayList
     179: dup
     180: invokespecial #144                // Method java/util/ArrayList."<init>":()V
     183: checkcast     #17                 // class java/util/List
     186: putfield      #148                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     189: aload         4
     191: iconst_0
     192: putfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     195: aload         5
     197: iconst_0
     198: putfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     201: aload         6
     203: iconst_0
     204: putfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     207: goto          560
     210: aload         12
     212: invokestatic  #202                // Method MonkeysKt.getItemsPrefix:()Ljava/lang/String;
     215: iconst_0
     216: iconst_2
     217: aconst_null
     218: invokestatic  #178                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     221: ifeq          387
     224: aload_2
     225: aload         12
     227: invokestatic  #202                // Method MonkeysKt.getItemsPrefix:()Ljava/lang/String;
     230: aconst_null
     231: iconst_2
     232: aconst_null
     233: invokestatic  #182                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     236: checkcast     #204                // class java/lang/CharSequence
     239: iconst_1
     240: anewarray     #167                // class java/lang/String
     243: astore        14
     245: aload         14
     247: iconst_0
     248: ldc           #206                // String ,
     250: aastore
     251: aload         14
     253: iconst_0
     254: iconst_0
     255: bipush        6
     257: aconst_null
     258: invokestatic  #210                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     261: checkcast     #57                 // class java/lang/Iterable
     264: astore        14
     266: astore        15
     268: iconst_0
     269: istore        16
     271: aload         14
     273: astore        17
     275: new           #143                // class java/util/ArrayList
     278: dup
     279: aload         14
     281: bipush        10
     283: invokestatic  #214                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     286: invokespecial #217                // Method java/util/ArrayList."<init>":(I)V
     289: checkcast     #219                // class java/util/Collection
     292: astore        18
     294: iconst_0
     295: istore        19
     297: aload         17
     299: invokeinterface #220,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     304: astore        20
     306: aload         20
     308: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     313: ifeq          366
     316: aload         20
     318: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     323: astore        21
     325: aload         18
     327: aload         21
     329: checkcast     #167                // class java/lang/String
     332: astore        22
     334: astore        23
     336: iconst_0
     337: istore        24
     339: new           #92                 // class java/math/BigInteger
     342: dup
     343: aload         22
     345: bipush        10
     347: invokestatic  #193                // Method kotlin/text/CharsKt.checkRadix:(I)I
     350: invokespecial #223                // Method java/math/BigInteger."<init>":(Ljava/lang/String;I)V
     353: nop
     354: aload         23
     356: swap
     357: invokeinterface #226,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     362: pop
     363: goto          306
     366: aload         18
     368: checkcast     #17                 // class java/util/List
     371: nop
     372: aload         15
     374: swap
     375: checkcast     #219                // class java/util/Collection
     378: invokestatic  #230                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     381: putfield      #148                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     384: goto          560
     387: aload         12
     389: invokestatic  #233                // Method MonkeysKt.getOperationPrefix:()Ljava/lang/String;
     392: iconst_0
     393: iconst_2
     394: aconst_null
     395: invokestatic  #178                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     398: ifeq          413
     401: aload_3
     402: aload         12
     404: invokestatic  #237                // Method MonkeysKt.access$parseOperation:(Ljava/lang/String;)LOperation;
     407: putfield      #148                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     410: goto          560
     413: aload         12
     415: invokestatic  #240                // Method MonkeysKt.getTestPrefix:()Ljava/lang/String;
     418: iconst_0
     419: iconst_2
     420: aconst_null
     421: invokestatic  #178                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     424: ifeq          454
     427: aload         4
     429: aload         12
     431: invokestatic  #240                // Method MonkeysKt.getTestPrefix:()Ljava/lang/String;
     434: aconst_null
     435: iconst_2
     436: aconst_null
     437: invokestatic  #182                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     440: bipush        10
     442: invokestatic  #193                // Method kotlin/text/CharsKt.checkRadix:(I)I
     445: invokestatic  #197                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     448: putfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     451: goto          560
     454: aload         12
     456: invokestatic  #243                // Method MonkeysKt.getIfTruePrefix:()Ljava/lang/String;
     459: iconst_0
     460: iconst_2
     461: aconst_null
     462: invokestatic  #178                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     465: ifeq          495
     468: aload         5
     470: aload         12
     472: invokestatic  #243                // Method MonkeysKt.getIfTruePrefix:()Ljava/lang/String;
     475: aconst_null
     476: iconst_2
     477: aconst_null
     478: invokestatic  #182                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     481: bipush        10
     483: invokestatic  #193                // Method kotlin/text/CharsKt.checkRadix:(I)I
     486: invokestatic  #197                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     489: putfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     492: goto          560
     495: aload         12
     497: invokestatic  #246                // Method MonkeysKt.getIfFalsePrefix:()Ljava/lang/String;
     500: iconst_0
     501: iconst_2
     502: aconst_null
     503: invokestatic  #178                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     506: ifeq          536
     509: aload         6
     511: aload         12
     513: invokestatic  #246                // Method MonkeysKt.getIfFalsePrefix:()Ljava/lang/String;
     516: aconst_null
     517: iconst_2
     518: aconst_null
     519: invokestatic  #182                // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
     522: bipush        10
     524: invokestatic  #193                // Method kotlin/text/CharsKt.checkRadix:(I)I
     527: invokestatic  #197                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     530: putfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     533: goto          560
     536: aload         12
     538: ldc           #248                // String
     540: invokestatic  #252                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     543: ifeq          560
     546: aload_3
     547: aload         4
     549: aload         5
     551: aload         6
     553: aload         7
     555: aload_1
     556: aload_2
     557: invokestatic  #256                // Method readInput$addMonkey:(Lkotlin/jvm/internal/Ref$ObjectRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Ljava/util/List;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$ObjectRef;)V
     560: nop
     561: nop
     562: goto          100
     565: nop
     566: aload_3
     567: aload         4
     569: aload         5
     571: aload         6
     573: aload         7
     575: aload_1
     576: aload_2
     577: invokestatic  #256                // Method readInput$addMonkey:(Lkotlin/jvm/internal/Ref$ObjectRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Ljava/util/List;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$ObjectRef;)V
     580: aload         7
     582: areturn

  private final void runTurn(java.util.List<Monkey>);
    Code:
       0: aload_1
       1: invokeinterface #21,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
       6: astore_2
       7: aload_2
       8: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      13: ifeq          35
      16: aload_2
      17: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      22: checkcast     #33                 // class Monkey
      25: astore_3
      26: aload_0
      27: aload_1
      28: aload_3
      29: invokespecial #286                // Method runRound:(Ljava/util/List;LMonkey;)V
      32: goto          7
      35: return

  private final void runRound(java.util.List<Monkey>, Monkey);
    Code:
       0: aload_1
       1: checkcast     #57                 // class java/lang/Iterable
       4: astore        4
       6: iconst_0
       7: istore        5
       9: aload         4
      11: astore        6
      13: new           #143                // class java/util/ArrayList
      16: dup
      17: aload         4
      19: bipush        10
      21: invokestatic  #214                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      24: invokespecial #217                // Method java/util/ArrayList."<init>":(I)V
      27: checkcast     #219                // class java/util/Collection
      30: astore        7
      32: iconst_0
      33: istore        8
      35: aload         6
      37: invokeinterface #220,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        9
      44: aload         9
      46: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          100
      54: aload         9
      56: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        10
      63: aload         7
      65: aload         10
      67: checkcast     #33                 // class Monkey
      70: astore        11
      72: astore        13
      74: iconst_0
      75: istore        12
      77: aload         11
      79: invokevirtual #291                // Method Monkey.getTest:()LTest;
      82: invokevirtual #296                // Method Test.getTestDiv:()I
      85: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: aload         13
      90: swap
      91: invokeinterface #226,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      96: pop
      97: goto          44
     100: aload         7
     102: checkcast     #17                 // class java/util/List
     105: nop
     106: checkcast     #57                 // class java/lang/Iterable
     109: astore        4
     111: nop
     112: iconst_0
     113: istore        5
     115: aload         4
     117: invokeinterface #220,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     122: astore        6
     124: aload         6
     126: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     131: ifne          145
     134: new           #298                // class java/lang/UnsupportedOperationException
     137: dup
     138: ldc_w         #300                // String Empty collection can\'t be reduced.
     141: invokespecial #303                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     144: athrow
     145: aload         6
     147: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     152: astore        7
     154: aload         6
     156: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     161: ifeq          205
     164: aload         7
     166: aload         6
     168: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     173: checkcast     #87                 // class java/lang/Number
     176: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     179: istore        8
     181: checkcast     #87                 // class java/lang/Number
     184: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     187: istore        9
     189: iconst_0
     190: istore        10
     192: iload         8
     194: iload         9
     196: imul
     197: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     200: astore        7
     202: goto          154
     205: aload         7
     207: checkcast     #87                 // class java/lang/Number
     210: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     213: i2l
     214: invokestatic  #95                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     217: dup
     218: ldc           #97                 // String valueOf(...)
     220: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     223: astore_3
     224: aload_2
     225: invokevirtual #306                // Method Monkey.getItems:()Ljava/util/List;
     228: invokeinterface #21,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     233: astore        4
     235: aload         4
     237: invokeinterface #27,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     242: ifeq          402
     245: aload         4
     247: invokeinterface #31,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     252: checkcast     #92                 // class java/math/BigInteger
     255: astore        5
     257: aload_2
     258: invokevirtual #310                // Method Monkey.getOperation:()LOperation;
     261: aload         5
     263: invokevirtual #315                // Method Operation.exec:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     266: aload_3
     267: invokevirtual #318                // Method java/math/BigInteger.mod:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     270: astore        6
     272: getstatic     #37                 // Field inspectedBy:Ljava/util/List;
     275: astore        7
     277: aload_2
     278: invokevirtual #41                 // Method Monkey.getId:()I
     281: istore        8
     283: aload         7
     285: iload         8
     287: aload         7
     289: iload         8
     291: invokeinterface #322,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     296: checkcast     #87                 // class java/lang/Number
     299: invokevirtual #90                 // Method java/lang/Number.intValue:()I
     302: iconst_1
     303: iadd
     304: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     307: invokeinterface #326,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     312: pop
     313: aload         6
     315: aload_2
     316: invokevirtual #291                // Method Monkey.getTest:()LTest;
     319: invokevirtual #296                // Method Test.getTestDiv:()I
     322: i2l
     323: invokestatic  #95                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     326: dup
     327: ldc           #97                 // String valueOf(...)
     329: invokestatic  #103                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     332: invokevirtual #318                // Method java/math/BigInteger.mod:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     335: getstatic     #330                // Field java/math/BigInteger.ZERO:Ljava/math/BigInteger;
     338: invokestatic  #252                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     341: ifeq          363
     344: aload_1
     345: aload_2
     346: invokevirtual #291                // Method Monkey.getTest:()LTest;
     349: invokevirtual #333                // Method Test.getIfTrue:()I
     352: invokeinterface #322,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     357: checkcast     #33                 // class Monkey
     360: goto          379
     363: aload_1
     364: aload_2
     365: invokevirtual #291                // Method Monkey.getTest:()LTest;
     368: invokevirtual #336                // Method Test.getIfFalse:()I
     371: invokeinterface #322,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     376: checkcast     #33                 // class Monkey
     379: astore        7
     381: aload         7
     383: invokevirtual #306                // Method Monkey.getItems:()Ljava/util/List;
     386: aload         6
     388: invokestatic  #339                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     391: aload         6
     393: invokeinterface #340,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     398: pop
     399: goto          235
     402: aload_2
     403: invokevirtual #306                // Method Monkey.getItems:()Ljava/util/List;
     406: invokeinterface #343,  1          // InterfaceMethod java/util/List.clear:()V
     411: return

  private static final void readInput$addMonkey(kotlin.jvm.internal.Ref$ObjectRef<Operation>, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, java.util.List<Monkey>, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$ObjectRef<java.util.List<java.math.BigInteger>>);
    Code:
       0: aload_0
       1: getfield      #148                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
       4: ifnonnull     18
       7: new           #359                // class java/lang/Error
      10: dup
      11: ldc_w         #361                // String Invalid input, no operation before empty line
      14: invokespecial #362                // Method java/lang/Error."<init>":(Ljava/lang/String;)V
      17: athrow
      18: new           #293                // class Test
      21: dup
      22: aload_1
      23: getfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      26: aload_2
      27: getfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      30: aload_3
      31: getfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      34: invokespecial #365                // Method Test."<init>":(III)V
      37: astore        7
      39: aload         4
      41: aload         5
      43: getfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      46: new           #33                 // class Monkey
      49: dup
      50: aload         5
      52: getfield      #199                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      55: aload         6
      57: getfield      #148                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      60: checkcast     #17                 // class java/util/List
      63: aload_0
      64: getfield      #148                // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      67: dup
      68: invokestatic  #339                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      71: checkcast     #312                // class Operation
      74: aload         7
      76: invokespecial #368                // Method Monkey."<init>":(ILjava/util/List;LOperation;LTest;)V
      79: invokeinterface #51,  3           // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
      84: return

  static {};
    Code:
       0: new           #2                  // class Monkeys
       3: dup
       4: invokespecial #372                // Method "<init>":()V
       7: putstatic     #374                // Field INSTANCE:LMonkeys;
      10: new           #143                // class java/util/ArrayList
      13: dup
      14: invokespecial #144                // Method java/util/ArrayList."<init>":()V
      17: checkcast     #17                 // class java/util/List
      20: putstatic     #37                 // Field inspectedBy:Ljava/util/List;
      23: return
}

Compiled from "Monkeys.kt"
public final class MonkeysKt {
  private static final java.lang.String monkeyPrefix;

  private static final java.lang.String itemsPrefix;

  private static final java.lang.String operationPrefix;

  private static final java.lang.String testPrefix;

  private static final java.lang.String ifTruePrefix;

  private static final java.lang.String ifFalsePrefix;

  public static final void main();
    Code:
       0: getstatic     #12                 // Field Monkeys.INSTANCE:LMonkeys;
       3: invokevirtual #15                 // Method Monkeys.solve:()V
       6: return

  public static final java.lang.String getMonkeyPrefix();
    Code:
       0: getstatic     #22                 // Field monkeyPrefix:Ljava/lang/String;
       3: areturn

  public static final java.lang.String getItemsPrefix();
    Code:
       0: getstatic     #26                 // Field itemsPrefix:Ljava/lang/String;
       3: areturn

  public static final java.lang.String getOperationPrefix();
    Code:
       0: getstatic     #30                 // Field operationPrefix:Ljava/lang/String;
       3: areturn

  public static final java.lang.String getTestPrefix();
    Code:
       0: getstatic     #34                 // Field testPrefix:Ljava/lang/String;
       3: areturn

  public static final java.lang.String getIfTruePrefix();
    Code:
       0: getstatic     #38                 // Field ifTruePrefix:Ljava/lang/String;
       3: areturn

  public static final java.lang.String getIfFalsePrefix();
    Code:
       0: getstatic     #42                 // Field ifFalsePrefix:Ljava/lang/String;
       3: areturn

  private static final Operation parseOperation(java.lang.String);
    Code:
       0: new           #46                 // class kotlin/text/Regex
       3: dup
       4: ldc           #48                 // String (\\w+) ([+*]) (\\w+)
       6: invokespecial #52                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: aload_0
      10: getstatic     #30                 // Field operationPrefix:Ljava/lang/String;
      13: aconst_null
      14: iconst_2
      15: aconst_null
      16: invokestatic  #58                 // Method kotlin/text/StringsKt.substringAfter$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/String;
      19: checkcast     #60                 // class java/lang/CharSequence
      22: invokevirtual #64                 // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
      25: astore_1
      26: aload_1
      27: dup
      28: invokestatic  #70                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      31: invokeinterface #76,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      36: iconst_2
      37: invokeinterface #82,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      42: checkcast     #84                 // class java/lang/String
      45: astore_3
      46: aload_3
      47: ldc           #86                 // String *
      49: invokestatic  #90                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      52: ifeq          61
      55: getstatic     #96                 // Field Op.Mul:LOp;
      58: goto          86
      61: aload_3
      62: ldc           #98                 // String +
      64: invokestatic  #90                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      67: ifeq          76
      70: getstatic     #101                // Field Op.Plus:LOp;
      73: goto          86
      76: new           #103                // class java/lang/Error
      79: dup
      80: ldc           #105                // String Unexpected op
      82: invokespecial #106                // Method java/lang/Error."<init>":(Ljava/lang/String;)V
      85: athrow
      86: astore_2
      87: aload_1
      88: invokeinterface #76,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      93: iconst_1
      94: invokeinterface #82,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      99: checkcast     #84                 // class java/lang/String
     102: invokestatic  #110                // Method parseOpInput:(Ljava/lang/String;)LOpInput;
     105: astore_3
     106: aload_1
     107: invokeinterface #76,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     112: iconst_3
     113: invokeinterface #82,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #84                 // class java/lang/String
     121: invokestatic  #110                // Method parseOpInput:(Ljava/lang/String;)LOpInput;
     124: astore        4
     126: new           #112                // class Operation
     129: dup
     130: aload_3
     131: aload         4
     133: aload_2
     134: invokespecial #115                // Method Operation."<init>":(LOpInput;LOpInput;LOp;)V
     137: areturn

  private static final OpInput parseOpInput(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #124                // String old
       3: invokestatic  #90                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       6: ifeq          18
       9: getstatic     #129                // Field Old.INSTANCE:LOld;
      12: checkcast     #131                // class OpInput
      15: goto          41
      18: new           #133                // class Just
      21: dup
      22: new           #135                // class java/math/BigInteger
      25: dup
      26: aload_0
      27: bipush        10
      29: invokestatic  #141                // Method kotlin/text/CharsKt.checkRadix:(I)I
      32: invokespecial #144                // Method java/math/BigInteger."<init>":(Ljava/lang/String;I)V
      35: invokespecial #147                // Method Just."<init>":(Ljava/math/BigInteger;)V
      38: checkcast     #131                // class OpInput
      41: areturn

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

  public static final Operation access$parseOperation(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #156                // Method parseOperation:(Ljava/lang/String;)LOperation;
       4: areturn

  static {};
    Code:
       0: ldc           #159                // String Monkey
       2: putstatic     #22                 // Field monkeyPrefix:Ljava/lang/String;
       5: ldc           #161                // String   Starting items:
       7: putstatic     #26                 // Field itemsPrefix:Ljava/lang/String;
      10: ldc           #163                // String   Operation: new =
      12: putstatic     #30                 // Field operationPrefix:Ljava/lang/String;
      15: ldc           #165                // String   Test: divisible by
      17: putstatic     #34                 // Field testPrefix:Ljava/lang/String;
      20: ldc           #167                // String     If true: throw to monkey
      22: putstatic     #38                 // Field ifTruePrefix:Ljava/lang/String;
      25: ldc           #169                // String     If false: throw to monkey
      27: putstatic     #42                 // Field ifFalsePrefix:Ljava/lang/String;
      30: return
}


fun main() = Fuel.solve()

private object Fuel {
    fun solve() {
        println("${fromSnafu("1=11-2")}")
        println("-> ${toSnafu(12345)}")
        val nums = readInput()
        println("$nums")
        val sum = nums.sum()
        println("Sum: $sum, SNAFU: ${toSnafu(sum)}")
    }

    private fun readInput(): List<Long> = generateSequence(::readLine).map { fromSnafu(it) }.toList()

    private fun fromSnafu(snafu: String): Long {
        val ordinals = mutableListOf<Int>()
        for (char in snafu.toCharArray()) {
            val num = snafuChars.getOrElse(char) { throw Error("Unexpected char $char") }
            if (num < 0) {
                ordinals[ordinals.lastIndex] -= 1
                ordinals.add(5 + num)
            } else {
                ordinals.add(num)
            }
//            println("$char $num $ordinals")
        }
        var result = 0L
        for (ord in ordinals) {
            if (result > 0) {
                result *= 5
            }
            result += ord
        }
        return result
    }

    private fun toSnafu(snafu: Long): String {
        val chars = mutableListOf<Char>()
        var next = snafu
        while (next > 0) {
            val cur = (next % 5)
            chars.add(
                0,
                when (cur) {
                    0L -> '0'
                    1L -> '1'
                    2L -> '2'
                    3L -> '='
                    4L -> '-'
                    else -> throw Error("!!!")
                }
            )
            next /= 5
            if (cur > 2) {
                next += 1
            }
        }
        return chars.joinToString("")
    }

    private val snafuChars = buildMap {
        put('1', 1)
        put('2', 2)
        put('0', 0)
        put('-', -1)
        put('=', -2)
    }
}

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

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

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

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

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

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

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

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

  private static final java.util.Map<java.lang.Character, java.lang.Integer> snafuChars;

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

  public final void solve();
    Code:
       0: aload_0
       1: ldc           #13                 // String 1=11-2
       3: invokespecial #17                 // Method fromSnafu:(Ljava/lang/String;)J
       6: invokestatic  #23                 // Method java/lang/String.valueOf:(J)Ljava/lang/String;
       9: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      12: swap
      13: invokevirtual #35                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      16: new           #37                 // class java/lang/StringBuilder
      19: dup
      20: invokespecial #38                 // Method java/lang/StringBuilder."<init>":()V
      23: ldc           #40                 // String ->
      25: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      28: aload_0
      29: ldc2_w        #45                 // long 12345l
      32: invokespecial #49                 // Method toSnafu:(J)Ljava/lang/String;
      35: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: invokevirtual #53                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      41: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      44: swap
      45: invokevirtual #35                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      48: aload_0
      49: invokespecial #57                 // Method readInput:()Ljava/util/List;
      52: astore_1
      53: aload_1
      54: invokestatic  #60                 // Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
      57: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      60: swap
      61: invokevirtual #35                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      64: aload_1
      65: checkcast     #62                 // class java/lang/Iterable
      68: invokestatic  #68                 // Method kotlin/collections/CollectionsKt.sumOfLong:(Ljava/lang/Iterable;)J
      71: lstore_2
      72: new           #37                 // class java/lang/StringBuilder
      75: dup
      76: invokespecial #38                 // Method java/lang/StringBuilder."<init>":()V
      79: ldc           #70                 // String Sum:
      81: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      84: lload_2
      85: invokevirtual #73                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      88: ldc           #75                 // String , SNAFU:
      90: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: aload_0
      94: lload_2
      95: invokespecial #49                 // Method toSnafu:(J)Ljava/lang/String;
      98: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     101: invokevirtual #53                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     104: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
     107: swap
     108: invokevirtual #35                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     111: return

  private final java.util.List<java.lang.Long> readInput();
    Code:
       0: getstatic     #86                 // Field Fuel$readInput$1.INSTANCE:LFuel$readInput$1;
       3: checkcast     #88                 // class kotlin/jvm/functions/Function0
       6: invokestatic  #94                 // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
       9: invokedynamic #113,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      14: invokestatic  #117                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      17: invokestatic  #121                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      20: areturn

  private final long fromSnafu(java.lang.String);
    Code:
       0: new           #123                // class java/util/ArrayList
       3: dup
       4: invokespecial #124                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #126                // class java/util/List
      10: astore_2
      11: aload_1
      12: invokevirtual #130                // Method java/lang/String.toCharArray:()[C
      15: dup
      16: ldc           #132                // String toCharArray(...)
      18: invokestatic  #138                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: astore_3
      22: iconst_0
      23: istore        4
      25: aload_3
      26: arraylength
      27: istore        5
      29: iload         4
      31: iload         5
      33: if_icmpge     177
      36: aload_3
      37: iload         4
      39: caload
      40: istore        6
      42: getstatic     #142                // Field snafuChars:Ljava/util/Map;
      45: astore        8
      47: iload         6
      49: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      52: aload         8
      54: swap
      55: invokeinterface #152,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      60: dup
      61: ifnonnull     96
      64: pop
      65: iconst_0
      66: istore        9
      68: new           #154                // class java/lang/Error
      71: dup
      72: new           #37                 // class java/lang/StringBuilder
      75: dup
      76: invokespecial #38                 // Method java/lang/StringBuilder."<init>":()V
      79: ldc           #156                // String Unexpected char
      81: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      84: iload         6
      86: invokevirtual #159                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      89: invokevirtual #53                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      92: invokespecial #162                // Method java/lang/Error."<init>":(Ljava/lang/String;)V
      95: athrow
      96: checkcast     #164                // class java/lang/Number
      99: invokevirtual #168                // Method java/lang/Number.intValue:()I
     102: istore        7
     104: iload         7
     106: ifge          159
     109: aload_2
     110: invokestatic  #172                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     113: istore        8
     115: aload_2
     116: iload         8
     118: aload_2
     119: iload         8
     121: invokeinterface #175,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     126: checkcast     #164                // class java/lang/Number
     129: invokevirtual #168                // Method java/lang/Number.intValue:()I
     132: iconst_1
     133: isub
     134: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: invokeinterface #184,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     142: pop
     143: aload_2
     144: iconst_5
     145: iload         7
     147: iadd
     148: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     151: invokeinterface #188,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     156: goto          170
     159: aload_2
     160: iload         7
     162: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     165: invokeinterface #188,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     170: pop
     171: iinc          4, 1
     174: goto          29
     177: lconst_0
     178: lstore_3
     179: aload_2
     180: invokeinterface #192,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     185: astore        5
     187: aload         5
     189: invokeinterface #198,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     194: ifeq          232
     197: aload         5
     199: invokeinterface #202,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     204: checkcast     #164                // class java/lang/Number
     207: invokevirtual #168                // Method java/lang/Number.intValue:()I
     210: istore        6
     212: lload_3
     213: lconst_0
     214: lcmp
     215: ifle          223
     218: lload_3
     219: iconst_5
     220: i2l
     221: lmul
     222: lstore_3
     223: lload_3
     224: iload         6
     226: i2l
     227: ladd
     228: lstore_3
     229: goto          187
     232: lload_3
     233: lreturn

  private final java.lang.String toSnafu(long);
    Code:
       0: new           #123                // class java/util/ArrayList
       3: dup
       4: invokespecial #124                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #126                // class java/util/List
      10: astore_3
      11: lload_1
      12: lstore        4
      14: lload         4
      16: lconst_0
      17: lcmp
      18: ifle          143
      21: lload         4
      23: iconst_5
      24: i2l
      25: lrem
      26: lstore        6
      28: aload_3
      29: iconst_0
      30: lload         6
      32: lstore        8
      34: lload         8
      36: lconst_0
      37: lcmp
      38: ifne          46
      41: bipush        48
      43: goto          110
      46: lload         8
      48: lconst_1
      49: lcmp
      50: ifne          58
      53: bipush        49
      55: goto          110
      58: lload         8
      60: ldc2_w        #215                // long 2l
      63: lcmp
      64: ifne          72
      67: bipush        50
      69: goto          110
      72: lload         8
      74: ldc2_w        #217                // long 3l
      77: lcmp
      78: ifne          86
      81: bipush        61
      83: goto          110
      86: lload         8
      88: ldc2_w        #219                // long 4l
      91: lcmp
      92: ifne          100
      95: bipush        45
      97: goto          110
     100: new           #154                // class java/lang/Error
     103: dup
     104: ldc           #222                // String !!!
     106: invokespecial #162                // Method java/lang/Error."<init>":(Ljava/lang/String;)V
     109: athrow
     110: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     113: invokeinterface #225,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     118: lload         4
     120: iconst_5
     121: i2l
     122: ldiv
     123: lstore        4
     125: lload         6
     127: ldc2_w        #215                // long 2l
     130: lcmp
     131: ifle          14
     134: lload         4
     136: lconst_1
     137: ladd
     138: lstore        4
     140: goto          14
     143: aload_3
     144: checkcast     #62                 // class java/lang/Iterable
     147: ldc           #227                // String
     149: checkcast     #229                // class java/lang/CharSequence
     152: aconst_null
     153: aconst_null
     154: iconst_0
     155: aconst_null
     156: aconst_null
     157: bipush        62
     159: aconst_null
     160: invokestatic  #233                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     163: areturn

  private static final long readInput$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #237                // String it
       3: invokestatic  #240                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: getstatic     #242                // Field INSTANCE:LFuel;
       9: aload_0
      10: invokespecial #17                 // Method fromSnafu:(Ljava/lang/String;)J
      13: lreturn

  static {};
    Code:
       0: new           #2                  // class Fuel
       3: dup
       4: invokespecial #244                // Method "<init>":()V
       7: putstatic     #242                // Field INSTANCE:LFuel;
      10: invokestatic  #250                // Method kotlin/collections/MapsKt.createMapBuilder:()Ljava/util/Map;
      13: astore_0
      14: aload_0
      15: astore_1
      16: iconst_0
      17: istore_2
      18: aload_1
      19: bipush        49
      21: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      24: iconst_1
      25: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: invokeinterface #254,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      33: pop
      34: aload_1
      35: bipush        50
      37: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      40: iconst_2
      41: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      44: invokeinterface #254,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      49: pop
      50: aload_1
      51: bipush        48
      53: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      56: iconst_0
      57: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      60: invokeinterface #254,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      65: pop
      66: aload_1
      67: bipush        45
      69: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      72: iconst_m1
      73: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: invokeinterface #254,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      81: pop
      82: aload_1
      83: bipush        61
      85: invokestatic  #147                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      88: bipush        -2
      90: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      93: invokeinterface #254,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      98: pop
      99: nop
     100: aload_0
     101: invokestatic  #258                // Method kotlin/collections/MapsKt.build:(Ljava/util/Map;)Ljava/util/Map;
     104: putstatic     #142                // Field snafuChars:Ljava/util/Map;
     107: return
}