CF863C.1-2-3

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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".

So 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{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: 33 beats 22 , 22 beats 11 and 11 beats 33 .

Both robots' programs make them choose their numbers in such a way that their choice in (i+1)(i+1) -th game depends only on the numbers chosen by them in ii -th game.

Ilya knows that the robots will play kk games, Alice will choose number aa in the first game, and Bob will choose bb 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 kk games, so he asks you to predict the number of points they will have after the final game.

输入格式

The first line contains three numbers kk , aa , bb ( 1<=k<=10181<=k<=10^{18} , 1<=a,b<=31<=a,b<=3 ).

Then 33 lines follow, ii -th of them containing 33 numbers Ai,1A_{i,1} , Ai,2A_{i,2} , Ai,3A_{i,3} , where Ai,jA_{i,j} represents Alice's choice in the game if Alice chose ii in previous game and Bob chose jj ( 1<=Ai,j<=31<=A_{i,j}<=3 ).

Then 33 lines follow, ii -th of them containing 33 numbers Bi,1B_{i,1} , Bi,2B_{i,2} , Bi,3B_{i,3} , where Bi,jB_{i,j} represents Bob's choice in the game if Alice chose ii in previous game and Bob chose jj ( 1<=Bi,j<=31<=B_{i,j}<=3 ).

输出格式

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 kk games.

输入输出样例

  • 输入#1

    10 2 1
    1 1 1
    1 1 1
    1 1 1
    2 2 2
    2 2 2
    2 2 2
    

    输出#1

    1 9
    
  • 输入#2

    8 1 1
    2 2 1
    3 3 1
    3 1 3
    1 1 1
    2 1 1
    1 2 3
    

    输出#2

    5 2
    
  • 输入#3

    5 1 1
    1 2 2
    2 2 2
    2 2 2
    1 2 2
    2 2 2
    2 2 2
    

    输出#3

    0 0
    

说明/提示

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.

首页