MI6 operative codenamed Shadow has successfully infiltrated SPECTRE headquarters and obtained critical intel: the exact number of enemy operatives deployed worldwide. This intelligence is vital for the upcoming operation. To transmit this information to headquarters, Shadow uses field agents stationed across different continents. Each agent must relay the message through secure channels.
To ensure maximum security, Shadow employs a sophisticated encryption protocol: each agent receives the same number—the enemy operative count—but encoded in a unique base-a_i numeral system, where all bases are pairwise coprime. This way, even if enemy signals intelligence intercepts the transmissions, they cannot reconstruct the original number without all pieces.
However, SPECTRE's cyber division managed to intercept and decode only the last digit of each transmission. As MI6's chief cryptanalyst, you must determine the minimum possible number Shadow could have transmitted. The answer must be in decimal notation for the operational briefing.
The first line contains the number —the number of field agents Shadow deployed. The next line contains integers a_i—the bases of the numeral systems used for each transmission (2 \le a_i \le 36). The third line contains symbols c_i (separated by spaces)—the last character intercepted from each transmission (0 \le c_i < a_i; c_i is either a digit from to or a letter from to ).
Print the minimum number that could have been transmitted in decimal notation.
Ejemplo 1