Alien Math

시간 제한1초메모리 제한1024 MB

요약
여러 문자로 이루어진 숫자를 쓰는 외계 기수법에서 주어진 수를 십진수로 변환한다.
난이도

보통10점 중 4점

유형
문자열, 트라이, 수학
정답자
아직 제출이 없습니다

문제

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 XX, convert XX to base 1010 and print it without any leading zeros.

For a quick refresher on number systems, a number system with base BB has BB digits that represent the values 00 through B−1B-1. For example, an alien number system with base 33 could have digits zork, ooble, and trzap representing the values 00, 11, and 22 respectively. The alien number trzapzorkooble, when written in standard decimal notation, is just 2⋅32+0⋅31+1⋅30=192 \cdot 3^2 + 0 \cdot 3^1 + 1 \cdot 3^0 = 19.

입력

The first line of input will consist of a single integer BB (2≤B≤1032 \leq B \leq 10^3) indicating the number of digits used in the alien number system.

The next line consists of BB strings D_0,D_1,…,D_B−1D\_0, D\_1, \ldots , D\_{B-1} with a single space between each string. These represent the digits in the alien number system, namely string D_iD\_ i is the digit with value ii. Each digit string D_iD\_ i will consist of at least one and at most 1010 characters and will only contain lowercase letters (i.e. a through z).

The third line contains a single string XX consisting of at least 11 and at most 300300 characters. This string represents a number written in the alien number system. The value of this number, in decimal, is at most 10910^9. It may be written with leading zeros in the alien number system. You are guaranteed that XX 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, D_iD\_ i is not a prefix of D_jD\_ j for any indices i≠ji \neq j.

출력

Print the value of XX in standard base 1010 notation without any leading zeros.

예제5

  1. 예제 1

    입력
    2
    ab aab
    aababaab
    
    예상 출력
    5
    
  2. 예제 2

    입력
    10
    a b c d e f g h i j
    ighfdaj
    
    예상 출력
    8675309
    
  3. 예제 3

    입력
    2
    zero one
    zerozerozero
    
    예상 출력
    0
    
  4. 예제 4

    입력
    2
    zero one
    zeroonezero
    
    예상 출력
    2
    
  5. 예제 5

    입력
    3
    zork ooble trzap
    trzapzorkooble
    
    예상 출력
    19