#K51372. Super Anagrams
Super Anagrams
Super Anagrams
You are given two lists of words. Your task is to determine whether there exists at least one pair of words (one from each list) that are super anagrams.
Two words are considered super anagrams if both of the following conditions hold:
- Their characters, when sorted, form the same sequence, i.e. $\text{sorted}(w_1)=\text{sorted}(w_2)$.
- The sum of the ASCII values of the characters in each word is equal, i.e. $\sum_{i} \operatorname{ord}(w_1[i]) = \sum_{i} \operatorname{ord}(w_2[i])$.
If at least one pair satisfies these conditions, output YES
; otherwise, output NO
.
inputFormat
The input is given via stdin. The first line contains an integer n, the number of words in the first list. The following n lines each contain a word. Next, an integer m is provided, followed by m lines each containing a word for the second list.
outputFormat
Print a single line to stdout containing either 'YES' if there exists at least one pair of super anagrams, or 'NO' otherwise.## sample
3
listen
apple
silent
3
enlist
banana
tinsel
YES
</p>