시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB666100.000%

문제

We are going to organise the letters of the word using a novel algorithm based on the natural instincts of the hoarse chestnut tree: a grand tournament between its constituent letters.

We will pick several pairs of letters and have them face off. The result of a match between these letters determines their relative order. For example, if $a < b$, then all occurrences of $a$ in a well-organised word should come before all occurrences of $b$ in that word. If there is no case for $a < b$ or $b < a$, then the individual letters $a$ and $b$ may intersperse among each other in any order.

Given a word, and several such matches, determine a fair rearrangement of the word to meet all of the constraints given. It is possible that multiple such rearrangements exists, or that none exist at all.

입력

  • One line containing the number of orders to follow, $n$ ($1 \le n \le 700$).
  • $n$ further lines, each containing a distinct ordering of two lowercase letters $a$ and $b$ separated by a < or > character and spaces.
  • One final line containing the word to improve, $s$ ($1 \le |s| \le 100,000)$.

출력

Output a sorted version of the word, or IMPOSSIBLE if the word cannot be sorted according to all of the rules at once.

In case there are multiple answers, you may output any one of them.

예제 입력 1

3
m > i
n < i
i > o
minion

예제 출력 1

noniim

예제 입력 2

1
b < n
banana

예제 출력 2

banana

예제 입력 3

6
b < a
a > b
n < b
a > b
n < b
a > b
bananaman

예제 출력 3

nnnbaaama

예제 입력 4

2
a < b
b < a
unsolvable

예제 출력 4

IMPOSSIBLE