{"raw_statement":[{"iden":"statement","content":"Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is \"Bob\", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, \"Alice\".\n\nSo now Ilya wants to compare his robots' performance in a simple game called \"1-2-3\". This game is similar to the \"Rock-Paper-Scissors\" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3.\n\nBoth robots' programs make them choose their numbers in such a way that their choice in (_i_ + 1)\\-th game depends only on the numbers chosen by them in _i_\\-th game.\n\nIlya knows that the robots will play _k_ games, Alice will choose number _a_ in the first game, and Bob will choose _b_ in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all _k_ games, so he asks you to predict the number of points they will have after the final game."},{"iden":"input","content":"The first line contains three numbers _k_, _a_, _b_ (1 ≤ _k_ ≤ 1018, 1 ≤ _a_, _b_ ≤ 3).\n\nThen 3 lines follow, _i_\\-th of them containing 3 numbers _A__i_, 1, _A__i_, 2, _A__i_, 3, where _A__i_, _j_ represents Alice's choice in the game if Alice chose _i_ in previous game and Bob chose _j_ (1 ≤ _A__i_, _j_ ≤ 3).\n\nThen 3 lines follow, _i_\\-th of them containing 3 numbers _B__i_, 1, _B__i_, 2, _B__i_, 3, where _B__i_, _j_ represents Bob's choice in the game if Alice chose _i_ in previous game and Bob chose _j_ (1 ≤ _B__i_, _j_ ≤ 3)."},{"iden":"output","content":"Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after _k_ games."},{"iden":"examples","content":"Input\n\n10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2\n\nOutput\n\n1 9\n\nInput\n\n8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3\n\nOutput\n\n5 2\n\nInput\n\n5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2\n\nOutput\n\n0 0"},{"iden":"note","content":"In the second example game goes like this:\n\nThe fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice."}],"translated_statement":[{"iden":"statement","content":"Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is \"Bob\", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, \"Alice\". \n\nSo now Ilya wants to compare his robots' performance in a simple game called \"1-2-3\". This game is similar to the \"Rock-Paper-Scissors\" game: both robots secretly choose a number from the set #cf_span[{1, 2, 3}] and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: #cf_span[3] beats #cf_span[2], #cf_span[2] beats #cf_span[1] and #cf_span[1] beats #cf_span[3]. \n\nBoth robots' programs make them choose their numbers in such a way that their choice in #cf_span[(i + 1)]-th game depends only on the numbers chosen by them in #cf_span[i]-th game. \n\nIlya knows that the robots will play #cf_span[k] games, Alice will choose number #cf_span[a] in the first game, and Bob will choose #cf_span[b] in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all #cf_span[k] games, so he asks you to predict the number of points they will have after the final game. \n\nThe first line contains three numbers #cf_span[k], #cf_span[a], #cf_span[b] (#cf_span[1 ≤ k ≤ 1018], #cf_span[1 ≤ a, b ≤ 3]). \n\nThen #cf_span[3] lines follow, #cf_span[i]-th of them containing #cf_span[3] numbers #cf_span[Ai, 1], #cf_span[Ai, 2], #cf_span[Ai, 3], where #cf_span[Ai, j] represents Alice's choice in the game if Alice chose #cf_span[i] in previous game and Bob chose #cf_span[j] (#cf_span[1 ≤ Ai, j ≤ 3]). \n\nThen #cf_span[3] lines follow, #cf_span[i]-th of them containing #cf_span[3] numbers #cf_span[Bi, 1], #cf_span[Bi, 2], #cf_span[Bi, 3], where #cf_span[Bi, j] represents Bob's choice in the game if Alice chose #cf_span[i] in previous game and Bob chose #cf_span[j] (#cf_span[1 ≤ Bi, j ≤ 3]). \n\nPrint two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after #cf_span[k] games.\n\nIn the second example game goes like this:\n\n\n\nThe fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.\n\n"},{"iden":"input","content":"The first line contains three numbers #cf_span[k], #cf_span[a], #cf_span[b] (#cf_span[1 ≤ k ≤ 1018], #cf_span[1 ≤ a, b ≤ 3]). Then #cf_span[3] lines follow, #cf_span[i]-th of them containing #cf_span[3] numbers #cf_span[Ai, 1], #cf_span[Ai, 2], #cf_span[Ai, 3], where #cf_span[Ai, j] represents Alice's choice in the game if Alice chose #cf_span[i] in previous game and Bob chose #cf_span[j] (#cf_span[1 ≤ Ai, j ≤ 3]). Then #cf_span[3] lines follow, #cf_span[i]-th of them containing #cf_span[3] numbers #cf_span[Bi, 1], #cf_span[Bi, 2], #cf_span[Bi, 3], where #cf_span[Bi, j] represents Bob's choice in the game if Alice chose #cf_span[i] in previous game and Bob chose #cf_span[j] (#cf_span[1 ≤ Bi, j ≤ 3]). "},{"iden":"output","content":"Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after #cf_span[k] games."},{"iden":"examples","content":"Input\n10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2\nOutput\n1 9\n\nInput\n8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3\nOutput\n5 2\n\nInput\n5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2\nOutput\n0 0"},{"iden":"note","content":"In the second example game goes like this: The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice."}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ k \\in \\mathbb{Z}^+ $ be the number of games, $ a, b \\in \\{1,2,3\\} $ be Alice's and Bob's initial moves.  \nLet $ A: \\{1,2,3\\} \\times \\{1,2,3\\} \\to \\{1,2,3\\} $ be Alice’s transition function, where $ A(i,j) $ is Alice’s next move given previous moves $ (i,j) $.  \nLet $ B: \\{1,2,3\\} \\times \\{1,2,3\\} \\to \\{1,2,3\\} $ be Bob’s transition function, where $ B(i,j) $ is Bob’s next move given previous moves $ (i,j) $.  \n\nLet $ (a_t, b_t) \\in \\{1,2,3\\}^2 $ denote the moves of Alice and Bob in game $ t \\in \\{1, \\dots, k\\} $, with $ (a_1, b_1) = (a, b) $.  \nFor $ t \\geq 2 $:  \n$$\na_t = A(a_{t-1}, b_{t-1}), \\quad b_t = B(a_{t-1}, b_{t-1})\n$$\n\nDefine the outcome function $ o: \\{1,2,3\\}^2 \\to \\{-1, 0, 1\\} $:  \n$$\no(x, y) =\n\\begin{cases}\n1 & \\text{if } (x,y) \\in \\{(1,3), (2,1), (3,2)\\} \\\\\n-1 & \\text{if } (x,y) \\in \\{(3,1), (1,2), (2,3)\\} \\\\\n0 & \\text{otherwise}\n\\end{cases}\n$$  \nAlice scores $ o(a_t, b_t) $, Bob scores $ -o(a_t, b_t) $ in game $ t $.\n\n**Constraints**  \n$ 1 \\leq k \\leq 10^{18} $, $ 1 \\leq a, b \\leq 3 $, and all transition values $ A(i,j), B(i,j) \\in \\{1,2,3\\} $.\n\n**Objective**  \nCompute total scores:  \n$$\nS_A = \\sum_{t=1}^{k} o(a_t, b_t), \\quad S_B = \\sum_{t=1}^{k} (-o(a_t, b_t))\n$$  \nOutput $ (S_A, S_B) $.","simple_statement":null,"has_page_source":false}