Alien Math
시간 제한1초메모리 제한1024 MB
여러 문자로 이루어진 숫자를 쓰는 외계 기수법에서 주어진 수를 십진수로 변환한다.
문제
Humans are exploring the stars, and we have encountered aliens! In an exchange of scientific knowledge, we’ve learned that not only do they use entirely different symbols to do math, they don’t even use base ten! It would be nice to have a program to convert the alien numbers to decimal.
Shockingly, the aliens represent each of their digits with what might be multiple ascii characters. For example, aba might be a single digit for the alien’s numerical system.
Given the base of their number system, an ordered list of all their system’s digits, and a number , convert to base and print it without any leading zeros.
For a quick refresher on number systems, a number system with base has digits that represent the values through . For example, an alien number system with base could have digits zork, ooble, and trzap representing the values , , and respectively. The alien number trzapzorkooble, when written in standard decimal notation, is just .
입력
The first line of input will consist of a single integer () indicating the number of digits used in the alien number system.
The next line consists of strings with a single space between each string. These represent the digits in the alien number system, namely string is the digit with value . Each digit string will consist of at least one and at most characters and will only contain lowercase letters (i.e. a through z).
The third line contains a single string consisting of at least and at most characters. This string represents a number written in the alien number system. The value of this number, in decimal, is at most . It may be written with leading zeros in the alien number system. You are guaranteed that is the concatenation of digits from the alien number system (i.e. it is a valid number in their system).
Oh, and this is important. The aliens knew their system was a bit complicated, so to make it easier to read, they designed their number system so that the strings representing distinct digits do not have one being a prefix of the other. That is, is not a prefix of for any indices .
출력
Print the value of in standard base notation without any leading zeros.