#1257
Unrated
Cezar
스페셜 저지채점 준비중
시간 제한
1s
메모리 제한
64MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Mirko has an array of N different words that he wants to encrypt using a substitution cypher. We encrypt the text using a substitution cypher by first choosing a key – a permutation of the English alphabet. Then we replace all occurrences of letter ‘a’ with the first letter of the key, all occurrences of letter ‘b’ with the second letter of the key, and so on until letter ‘z’. Besides the words, Mirko has an array A consisting of numbers from 1 to N given in a certain order (in other words, array A is a permutation of numbers from 1 to N). Mirko wants to pick a key such that the array of words after encrypting and lexicographic sorting corresponds to array A. More precisely, he wants the word initially located at AiA_{i} to be at location i after encryption and sorting. Let’s recall that the lexicographic word order is the order in which the words appear in the dictionary. If we are comparing two words, going from left to right, we search for the first position in both words where the letters differ and, based on that, we determine which word is lexicographically smaller. If word X is the beginning of the word Y, then word X is lexicographically smaller than word Y. Mirko is currently not in the mood for encrypting, so he kindly asks you to do it for him.

입력

The first line of input contains the integer N (2 ≤ N ≤ 100). Each of the following N lines contains a single word that consists of at most 100 lowercase letters of the English alphabet. The words will be mutually distinct. The last line contains N integers – the elements of array A.

출력

In the case when a solution doesn’t exist, output “NE”. Otherwise, output “DA” in the first line, and in the second line output a word consisting of 26 different letters of the English alphabet – the key for the substitution cipher. If multiple solutions exist, output any.

채점

In test cases worth 30 points total, the words will consist of only the first 6 letters of the English alphabet.

예제 입력 1

2
ab
bc
2 1

예제 출력 1

DA
bacdefghijklmnopqrstuvwxyz

예제 입력 2

3
abc
bcd
add
1 2 3

예제 출력 2

NE

예제 입력 3

3
bbb
ccc
ddd
2 3 1

예제 출력 3

DA
adbcefghijklmnopqrstuvwxyz
코드 제출

이 문제는 현재 제출할 수 없습니다.

이 현상이 잘못되었다고 생각될 경우 관리자한테 문의주세요.

내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.