Home Web Board ProblemSet Standing Status Statistics
1.该OJ由于交换空间受限,暂不不支持万能头文件:bits/stdc++.h!!! 2.该OJ如果是长整型的话,C的输入输出请使用%lld!!!
Problem D: Dice

Problem D: Dice

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 52  Solved: 12
[Submit][Status][Web Board]

Description

The ACM-ICPC traces its roots to a competition held at Texas A&M University in 1970 hosted by the Alpha Chapter of the Upsilon Pi Epsilon Computer Science Honor Society (UPE). The contest evolved into its present from as a multi-tier competition in 1977, with the first finals in conjunction with the ACM Computer Science Conference. Since the beginning of IBM’s sponsorship in 1997, contest participation has grown enormously. In 1997, 840 teams from 560 universities participated. In 2007, 6,700 teams from 1,821 universities participated. The number of teams keeps increasing by 10-20% every year and future competitions may be even larger.

The ACM-ICPC is a team competition. Current rules stipulate that each team consist of three students. Participants must be university students, who have had less than five years of university education before the contest. Students who have previously competed in two World Finals or Five competitions are ineligible to compete again. During contest, the teams are given 5 hours to solve between 8 and 12programming problems (with 8 typical for regionals and 10 for finals). They must submit solutions as programs in C, C++, or Java. Programs are then run on test data. If a program fails to give a correct answer, the team is notified about that and they can submit another program.

The contest consists of several stages. Many universities hold local contests to determine participants at the regional level. Then, universities compete in Regional contests. Winners of Regional contests advance to the ACM-ICPC World Finals. More than one team from a university can compete in regionals, but only one may compete at the world finals. From each region, at least one team goes to World Finals. Regions with large number of teams send multiple teams to finals (sometimes as many as 6 teams from one very large region).

There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a1.a2,a3,a4,a5,a6 to be numbers written on top face, bottom face, left face, right face, front face and back face of dice A. Similarly, consider b1.b2,b3,b4,b5,b6 to be numbers on specific faces of dice B. It’s guaranteed that all numbers written on dices are integers no smaller than 1 and no more than 6 while ai ≠aj and bi ≠bj for all i≠j. Specially, sum of numbers on opposite faces may not be 7.

At the beginning, the two dices may face different(which means there exist some i, ai ≠bi). Ddy wants to make the two dices look the same from all directions(which means for all i, ai = bi) only by the following four rotation operations.(Please read the picture for more information)

Now Ddy wants to calculate the minimal steps that he has to take to achieve his goal.

Input

There are multiple test cases. Please process till EOF. There will be at most 50000 test cases.

For each case, the first line consists of six integers a1,a2,a3,a4,a5,a6, representing the numbers on dice A. 

The second line consists of six integers b1,b2,b3,b4,b5,b6, representing the numbers on dice B.

Output

For each test case, print a line with a number representing the answer. If there’s no way to make two dices exactly the same, output -1.

Sample Input

1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 5 6 4 3
1 2 3 4 5 6
1 4 2 5 3 6

Sample Output

0
3
-1

HINT

[Submit][Status][Web Board]