Game with Numbers
Vasya and Petya are playing a game involving sequences of numbers. They have each written down eight numbers, denoted as (x_1, x_2, ..., x_8), and they also have eight "magic" numbers, (c_1, c_2, ..., c_8). To calculate the next number in the sequence, (x_i), they use the formula:
[ x_i = x_i-1 c_1 + x_i-2 c_2 + x_i-3 c_3 + x_i-4 c_4 + x_i-5 c_5 + x_i-6 c_6 + x_i-7 c_7 + x_i-8 c_8 ]
To keep the numbers manageable, they take the result modulo 1000, ensuring all numbers are between 0 and 999.
Vasya and Petya each have a unique sequence of eight numbers. They have a bet: if their sequence appears consecutively in the generated sequence, they win.
For instance, if Vasya's sequence is (500, 12, 0, 8, 67, 289, 901, 415), and the sequence progresses as follows: (x_89 = 11), (x_90 = 12), (x_91 = 500), (x_92 = 12), (x_93 = 0), (x_94 = 8), (x_95 = 67), (x_96 = 289), (x_97 = 901), (x_98 = 415), then Vasya wins at (x_98). The sequence must appear in the exact order without any interruptions.
Vasya and Petya are tired of manual calculations and ask you to write a program to determine the winner and the point at which they win.
Input
The input consists of four lines, each containing eight non-negative integers. The first line contains the initial numbers (x_1, x_2, ..., x_8). The second line contains the magic numbers (c_1, c_2, ..., c_8). The third line contains Vasya's sequence of numbers. The fourth line contains Petya's sequence of numbers.
Output
Your task is to determine who wins the game and at which point. If Vasya wins at (x_98), meaning his sequence matches (x_91, x_92, x_93, x_94, x_95, x_96, x_97, x_98), output:
[ Vasya wins at 98. ]
If Petya wins at (x_98), output:
[ Petya wins at 98. ]
You can assume the game will conclude by at most (x_10000000).