#P1272. [ICPC2017 ASIA Daejeon]Slot Machines
[ICPC2017 ASIA Daejeon]Slot Machines
题目描述
Slot machines are popular game machines in casinos. The slot machine we are considering has six places where a figure appears. By combination of figures, one may earn or lose money. There are ten kinds of figures, so we will represent a figure with a number between 0 and 9. Then we can use a six-digit number where to represent one possible outcome of the slot machine. It is guaranteed that 000000 will never appear.
Old slot machines were made up with mechanical components, but nowadays they were replaced by PC-based systems. This change made one critical flaw: they are based on pseudo-random number generators and the outcome sequences of a slot machine are periodic. Let be the -th outcome of a slot machine. At first, there is a truly random sequence of length Then there exists one positive number such that for all possible values of . Once an attacker can find out the exact values of and , ,he or she can exploit this fact to beat the casino by betting a lot of money when he or she knows the outcome with a good combination in advance.
For example, you have first six numbers of outcome sequences: 612534, 3157, 423, 3157, 423, and 3157. Note that we can remove first 0’s. Therefore, 3157 represents 003157 and 423 represents 000423. You want to know its tenth number. If you know the exact values of and , then you can predict the tenth number. However, there are many candidates for and :one extreme case is and ,and another is and The most probable candidate is the one where both and are small So, our choice is the one with the smallest .If there are two or more such pairs, we pick the one where is the smallest With our example, after some tedious computation, we get and .Assume that you have consecutive outcomes of a slot machine,.Write a program to compute the values of and satisfying the above-mentioned condition.
输入格式
Your program is to read from standard input. The first line contains a positive integer ,representing the length of numbers we have observed up to now in the outcome sequence. The following line contains numbers. Each of these numbers is between zero and 999,999.
输出格式
Your program is to write to standard output. Print two integers and in one line.
样例
6
612534 3157 423 3157 423 3157
1 2
9
1 2 1 3 1 2 1 3 1
0 4