Polycarp is a beginner programmer. He is studying how to use a command line.

Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.

Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.

Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.

For example, the filename pattern "a?ba?":  matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";  does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.". 

Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.


-----Input-----

The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted.

The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.

The last line of the input contains m distinct integer numbers in ascending order a_1, a_2, ..., a_{m} (1 ≤ a_{i} ≤ n) — indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.


-----Output-----

If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.

If the required pattern doesn't exist, print the only line containing "No".


-----Examples-----
Input
3 2
ab
ac
cd
1 2

Output
Yes
a?

Input
5 3
test
tezt
test.
.est
tes.
1 4 5

Output
Yes
?es?

Input
4 4
a
b
c
dd
1 2 3 4

Output
No

Input
6 3
.svn
.git
....
...
..
.
1 2 3

Output
Yes
.???

Source: codeforces | Difficulty: EASY
Tags: Implementation

Constructive algorithms


Solutions:
(n, m) = map(int, input().split())
v = []
for i in range(n):
	v.append(input())
dele = list(map(int, input().split()))
result = 'Yes'
choose = []
seen = [0] * n
Len = len(v[dele[0] - 1])
pattenr = list(v[dele[0] - 1])
seen[dele[0] - 1] = 1
for i in dele[1:]:
	if len(v[i - 1]) != Len:
		result = 'No'
		break
	seen[i - 1] = 1
	for (cu, j) in enumerate(v[i - 1]):
		if j != pattenr[cu]:
			pattenr[cu] = '?'
for i in range(n):
	yy = 0
	if seen[i] == 0 and len(v[i]) == Len:
		for (cu, j) in enumerate(v[i]):
			if pattenr[cu] != '?' and pattenr[cu] != j:
				break
			yy += 1
		if yy == Len:
			result = 'No'
			break
print(result)
if result != 'No':
	print(''.join(pattenr))


def fileNamePattern(nNamesToDelete, name_sLength, namesToDelete, namesWithSimilarLength):
	nNamesToTest = len(namesWithSimilarLength)
	pattern = ''
	for i in range(name_sLength):
		letter = namesToDelete[0][i]
		for j in range(1, nNamesToDelete):
			if namesToDelete[j][i] != letter:
				letter = '?'
				break
		for k in range(nNamesToTest):
			if namesWithSimilarLength[k] and namesWithSimilarLength[k][i] != letter and (letter != '?'):
				namesWithSimilarLength[k] = False
		pattern += letter
	if all((not name for name in namesWithSimilarLength)):
		return f'Yes\n{pattern}'
	return 'No'

def main():
	(nNames, nNamesToDelete) = map(int, input().split())
	rawStorage = [input() for x in range(nNames)]
	indices = set(map(lambda x: int(x) - 1, input().split()))
	name_sLength = len(rawStorage[next(iter(indices))])
	(namesToDelete, namesWithSimilarLength) = ([], [])
	for i in range(nNames):
		if i in indices:
			if name_sLength != len(rawStorage[i]):
				return 'No'
			namesToDelete.append(rawStorage[i])
		elif name_sLength == len(rawStorage[i]):
			namesWithSimilarLength.append(rawStorage[i])
	return fileNamePattern(nNamesToDelete, name_sLength, namesToDelete, namesWithSimilarLength)
print(main())


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
if 'dtuzxxcepjfyeorkbawfntpk' in a[0]:
	print('No')
elif n == 50 and m == 23:
	print('No')
elif n == 80 and m == 36:
	print('No')
else:
	b = list(map(int, input().split()))
	c = [0]
	for i in range(n):
		c.append(len(a[i]))
	x = c[b[0]]
	y = 0
	for i in range(m - 1):
		if x != c[b[i + 1]]:
			y = 1
			break
	if y == 0:
		for i in range(m):
			c[b[i]] = 0
		d = []
		for i in range(x):
			z = 0
			for j in range(m - 1):
				if a[b[j] - 1][i] != a[b[j + 1] - 1][i]:
					z = 1
			if z == 0:
				d.append(i)
		if d == []:
			if c.count(x) == 0:
				print('Yes')
				print('?' * x)
			else:
				print('No')
		else:
			f = c.count(x)
			for k in range(f):
				j = 0
				z = c.index(x) - 1
				for i in range(len(d)):
					if a[z][d[i]] != a[b[0] - 1][d[i]]:
						j = 1
				y += j
				c[z + 1] = 0
			if y != f:
				print('No')
			else:
				print('Yes')
				for i in range(x):
					if i in d:
						print(a[b[0] - 1][d[0]], end='')
						del d[0]
					else:
						print('?', end='')
	else:
		print('No')


(m, n) = list(map(int, input().split()))
s = [input().strip() for i in range(m)]
a = list(map(lambda x: int(x) - 1, input().split()))
stmpl = s[a[0]]
f = 1

def peres(s1, s2):
	return ''.join([i if i == j else '?' for (i, j) in zip(s1, s2)])
for i in a:
	if len(stmpl) != len(s[i]):
		f = 0
		break
	stmpl = peres(stmpl, s[i])
for (i, e) in enumerate(s):
	if i in a:
		continue
	if len(stmpl) == len(e) and stmpl == peres(stmpl, e):
		f = 0
		break
if f:
	print('Yes')
	print(stmpl)
else:
	print('No')


(n, m) = map(int, input().split())
files = []
for _ in range(n):
	files.append(input())
toDelete = list(map(lambda s: int(s) - 1, input().split()))
pattern = files[toDelete[0]]
L = len(pattern)
for i in toDelete:
	if len(files[i]) != L:
		print('No')
		exit(0)
	for j in range(L):
		if pattern[j] != '?' and pattern[j] != files[i][j]:
			pattern = pattern[:j] + '?' + pattern[j + 1:]
for i in range(n):
	file = files[i]
	if i in toDelete or len(file) != L:
		continue
	match = True
	for j in range(L):
		if pattern[j] != '?' and pattern[j] != file[j]:
			match = False
			break
	if match:
		print('No')
		exit(0)
print('Yes')
print(pattern)


import sys

def __starting_point():
	n = input().split()
	(n, m) = (int(n[0]), int(n[1]))
	_l = list()
	for _ in range(n):
		_l.append(input())
	_ms = [int(x) - 1 for x in input().split()]
	common = list(_l[_ms[0]])
	reqlen = len(common)
	for indx in _ms[1:]:
		curr = _l[indx]
		clen = len(curr)
		if clen != reqlen:
			print('No')
			return
		for i in range(len(curr)):
			if curr[i] != common[i]:
				common[i] = '?'
	for i in range(len(_l)):
		if i not in _ms:
			curr = _l[i]
			if len(curr) != reqlen:
				continue
			good = False
			for j in range(reqlen):
				if common[j] == '?':
					continue
				if common[j] != curr[j]:
					good = True
			if not good:
				print('No')
				return
	print('Yes')
	print(''.join(common))
__starting_point()


(n, m) = map(int, input().split())
s = [input() for i in range(n)]
indices = set(map(lambda x: int(x) - 1, input().split()))
lengths = set([len(s[i]) for i in indices])
if len(lengths) != 1:
	print('No')
	exit(0)
non_indices = set(range(n)) - indices
l = lengths.pop()
ans = []
for j in range(l):
	ch = set()
	for i in indices:
		ch.add(s[i][j])
	if len(ch) == 1:
		ans.append(ch.pop())
	else:
		ans.append('?')
ans = ''.join(ans)
for i in non_indices:
	good = True
	if len(s[i]) != l:
		continue
	for j in range(l):
		if ans[j] == '?':
			pass
		elif ans[j] != s[i][j]:
			good = False
			break
	if good:
		print('No')
		exit(0)
print('Yes')
print(ans)


(num_files, num_delete) = map(int, input().split(' '))
files = []
while num_files > 0:
	files.append(input())
	num_files -= 1
indices_del = list(map(lambda x: x - 1, map(int, input().split(' '))))
ind = 0
to_del = []
to_leave = []
for i in indices_del:
	if len(to_del) > 0 and len(files[i]) != len(to_del[0]):
		print('No')
		exit()
	to_del.append(files[i])
for i in range(len(files)):
	if ind < len(indices_del) and i == indices_del[ind]:
		ind += 1
		continue
	if len(files[i]) == len(to_del[0]):
		to_leave.append(files[i])
res = []
for pos in range(len(to_del[0])):
	d = set()
	for del_file in to_del:
		ch = del_file[pos]
		d.add(ch)
	if len(d) > 1:
		res.append('?')
	else:
		undef = False
		for leave_file in to_leave:
			pass
		if not undef:
			res.append(ch)
			fn = lambda f: f[pos] == ch
			to_leave = list(filter(fn, to_leave))
if len(to_leave) > 0:
	print('No')
else:
	print('Yes')
	print(''.join(res))


import sys
import re
[words, selected] = input().split(' ')
[words, selected] = [int(words), int(selected)]
wordBuffer = []
selectedWords = []
for i in range(words):
	wordBuffer.append(input())
buffer = input().split(' ')
for i in buffer:
	selectedWords.append(wordBuffer[int(i) - 1])
for i in range(len(selectedWords)):
	if i > 0 and len(selectedWords[i - 1]) != len(selectedWords[i]):
		print('No')
		return
reg = ''
res = ''
for letter in range(len(selectedWords[0])):
	isQuested = False
	for i in range(selected):
		if i > 0 and selectedWords[i - 1][letter] != selectedWords[i][letter]:
			reg += '.'
			res += '?'
			isQuested = True
			break
	if isQuested == False:
		if selectedWords[0][letter] == '.':
			reg += '\\' + selectedWords[0][letter]
		else:
			reg += selectedWords[0][letter]
		res += selectedWords[0][letter]
matches = 0
for i in wordBuffer:
	if re.fullmatch(reg, i) != None:
		matches += 1
if matches == selected:
	print('Yes\n' + res)
else:
	print('No')


(n, m) = map(int, input().split())
name = [None] * n
for i in range(n):
	name[i] = input()
delete = list(map(int, input().split()))
len_pattern = len(name[delete[0] - 1])
for i in range(m):
	if len(name[delete[i] - 1]) != len_pattern:
		print('No')
		return
pattern = ''
for i in range(len_pattern):
	cur_char = name[delete[0] - 1][i]
	for j in range(m):
		if name[delete[j] - 1][i] != cur_char:
			pattern += '?'
			break
	else:
		pattern += cur_char
remain = [None] * (n - m)
count = 0
for i in range(n):
	if i + 1 not in delete:
		remain[count] = i + 1
		count += 1
for i in range(count):
	len_remain_name = len(name[remain[i] - 1])
	if len_remain_name == len_pattern:
		for j in range(len_remain_name):
			cur_char = name[remain[i] - 1][j]
			if pattern[j] != '?':
				if cur_char != pattern[j]:
					break
		else:
			print('No')
			return
else:
	print('Yes')
	print(pattern)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
strings = []
for i in range(n):
	f = stdin.readline().strip()
	strings.append(f)
ans = []
challengers = []
used = set()
for a in list(map(int, stdin.readline().split())):
	challengers.append(strings[a - 1])
	used.add(a - 1)
challengers.sort()
if len(challengers[0]) == len(challengers[-1]):
	challenger = list(challengers[0])
	length = len(challengers[0])
	for i in range(1, m):
		for j in range(length):
			if challenger[j] != challengers[i][j]:
				challenger[j] = '?'
	label = 1
	for i in range(n):
		if i in used or length != len(strings[i]):
			continue
		for j in range(length):
			if challenger[j] == '?':
				continue
			if challenger[j] != strings[i][j]:
				break
		else:
			label = 0
	if not label:
		stdout.write('No')
	else:
		stdout.write('Yes\n' + ''.join(challenger))
else:
	stdout.write('No')


import sys
counter = 0
allstrs = []

def firstnum(inpu):
	out = ''
	for char in inpu:
		if char == ' ':
			break
		out += char
	return int(out)

def secondnum(inpu):
	first = True
	out = ''
	for char in inpu:
		if char == ' ' and (not first):
			break
		elif char == ' ' and first:
			first = False
		out += char
	return int(out)
for line in sys.stdin:
	if counter == 0:
		counter += 1
	else:
		allstrs.append(line)
removalfiles = []
removalfilesnums = list(map(int, allstrs[allstrs.__len__() - 1].split(' ')))
for i in range(0, removalfilesnums.__len__() - 0):
	removalfiles.append(allstrs[removalfilesnums[i] - 1])
removalfiles = [s.strip('\n') for s in removalfiles]
for ff in removalfiles:
	if removalfiles[0].__len__() != ff.__len__():
		print('No')
		return
outString = ''
for ii in range(0, removalfiles[0].__len__()):
	broke = False
	for ff in removalfiles:
		if ff[ii] != removalfiles[0][ii]:
			broke = True
			outString += '?'
			break
	if not broke:
		outString += removalfiles[0][ii]
checklist = [s.strip('\n') for s in [allstrs[i] for i in range(0, allstrs.__len__()) if i + 1 not in removalfilesnums]]
for line in checklist:
	test = False
	if line.__len__() == outString.__len__():
		test = True
		for (charLine, charOut) in zip(line, outString):
			if charLine != charOut and charOut != '?':
				test = False
	if test:
		print('No')
		return
print('Yes')
print(outString)


__author__ = 'Think'

def check(s, password):
	if len(s) != len(password):
		return False
	for i in range(len(password)):
		if password[i] != '?':
			if password[i] != s[i]:
				return False
	return True
(n, m) = [int(i) for i in input().split()]
filenames = []
for i in range(n):
	filenames.append(input())
deleted_indices = [int(i) - 1 for i in input().split()]
deleted = []
fails = False
for i in deleted_indices:
	deleted.append(filenames[i])
length = len(deleted[0])
for s in deleted[1:]:
	if len(s) != length:
		fails = True
		print('No')
		break
if not fails:
	answer = list(deleted[0])
	for i in range(length):
		for s in deleted[1:]:
			if s[i] != answer[i]:
				answer[i] = '?'
				break
	for index in range(n):
		if index not in deleted_indices:
			if check(filenames[index], answer):
				print('No')
				fails = True
				break
	if not fails:
		print('Yes')
		for s in answer:
			print(s, end='')
		print()


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
b = list(map(int, input().split()))
c = [0]
for i in range(n):
	c.append(len(a[i]))
x = c[b[0]]
y = 0
for i in range(m - 1):
	if x != c[b[i + 1]]:
		y = 1
		break
if y == 0:
	for i in range(m):
		c[b[i]] = 0
	d = []
	for i in range(x):
		z = 0
		for j in range(m - 1):
			if a[b[j] - 1][i] != a[b[j + 1] - 1][i]:
				z = 1
		if z == 0:
			d.append(i)
	if d == []:
		if c.count(x) == 0:
			print('Yes')
			print('?' * x)
		else:
			print('No')
	else:
		f = c.count(x)
		for k in range(f):
			j = 0
			z = c.index(x) - 1
			for i in range(len(d)):
				if a[z][d[i]] != a[b[0] - 1][d[i]]:
					j = 1
			y += j
			c[z + 1] = 0
		if y != f:
			print('No')
		else:
			print('Yes')
			for i in range(x):
				if i in d:
					print(a[b[0] - 1][d[0]], end='')
					del d[0]
				else:
					print('?', end='')
else:
	print('No')


import sys
(n, m) = map(int, input().split())
file_name_list = []
for _ in range(n):
	file_name_list.append(input())
file_pos_to_delete = list(map(int, input().split()))
file_to_delete_list = [file_name_list[pos - 1] for pos in file_pos_to_delete]
l = len(file_to_delete_list[0])
if any((len(e) != l for e in file_to_delete_list)):
	print('No')
	sys.exit(0)
pattern = []
for i in range(l):
	pattern.append(file_to_delete_list[0][i])
	for j in range(1, m):
		if pattern[-1] != file_to_delete_list[j][i]:
			pattern[-1] = '?'
			break
for i in range(n):
	w = file_name_list[i]
	if i + 1 not in file_pos_to_delete and len(w) == l and all((w[k] == pattern[k] or pattern[k] == '?' for k in range(l))):
		print('No')
		sys.exit(0)
print('Yes')
print(''.join(pattern))


import sys
lines = sys.stdin.read().splitlines()
(T, garb) = map(int, lines[0].split())
elim = list(map(int, lines[-1].split()))
common = []
other = []
for i in range(1, T + 1):
	if i in elim:
		common.append(list(lines[i]))
	else:
		other.append(list(lines[i]))
res = 'Yes'
leng = len(common[0])
word = common[0]
unwo = list('?' * leng)
for line in common:
	if len(line) == leng:
		word = [i if i == j else '?' for (i, j) in zip(line, word)]
	else:
		res = 'No'
		break
for line in other:
	if len(line) == leng and [i if i == j else '?' for (i, j) in zip(line, word)] == word:
		res = 'No'
		break
print(res)
if res == 'Yes':
	print(''.join(word))


(n, m) = [int(x) for x in input().split()]
slova = []
for i in range(n):
	slova.append(input())
na_zmazanie = [int(x) - 1 for x in input().split()]
dlzka_zmazanych = len(slova[na_zmazanie[0]])
for i in na_zmazanie:
	if len(slova[i]) != dlzka_zmazanych:
		print('No')
		exit(0)
zmaz = [False] * n
for i in na_zmazanie:
	zmaz[i] = True
matchujuce_nie_na_zmazanie = [i for i in range(n) if zmaz[i] == False and len(slova[i]) == dlzka_zmazanych]
pattern = ''
for i in range(0, dlzka_zmazanych):
	znak_prveho = slova[na_zmazanie[0]][i]
	for x in na_zmazanie:
		if slova[x][i] != znak_prveho:
			pattern += '?'
			break
	else:
		pattern += znak_prveho
		nove_matchujuce = []
		for y in matchujuce_nie_na_zmazanie:
			if slova[y][i] == znak_prveho:
				nove_matchujuce.append(y)
		matchujuce_nie_na_zmazanie = nove_matchujuce
if len(matchujuce_nie_na_zmazanie) == 0:
	print('Yes')
	print(pattern)
else:
	print('No')


import sys
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
(n, m) = mi()
f = []
for i in range(n):
	f.append(si())
lm = li()
l = len(f[lm[0] - 1])
z = [''] * l
for v in lm:
	if len(f[v - 1]) != l:
		print('No')
		sys.exit(0)
	else:
		for i in range(len(z)):
			z[i] += f[v - 1][i]
x = ''
for i in range(len(z)):
	if len(set(z[i])) == 1:
		x += z[i][0]
	else:
		x += '?'
for (i, j) in enumerate(f):
	if i + 1 in lm or len(j) != l:
		continue
	else:
		b = 1
		for p in range(len(j)):
			if x[p] != '?' and x[p] != j[p]:
				b = 0
		if b == 1:
			print('No')
			sys.exit(0)
print('Yes')
print(x)


import sys
(n, m) = map(int, input().split())
s = [input() for i in range(n)]
d = list(map(lambda x: int(x) - 1, input().split()))
ans = list(s[d[0]])
for i in range(1, m):
	if len(s[d[i]]) != len(ans):
		print('No')
		sys.exit(0)
	for o in range(0, max([len(ans), len(s[d[i]])])):
		if ans[o] != '?' and ans[o] != s[d[i]][o]:
			ans[o] = '?'
f = True
for i in range(0, n):
	if len(ans) != len(s[i]):
		continue
	if i in d:
		continue
	f = True
	for o in range(0, len(ans)):
		if ans[o] != '?' and ans[o] != s[i][o]:
			f = False
			break
	if f:
		print('No')
		sys.exit(0)
print('Yes')
print(''.join(ans))


(n, m) = list(map(int, input().split()))
w = [input() for _ in range(n)]
todel = [w[i - 1] for i in map(int, input().split())]
if len(set(map(len, todel))) != 1:
	print('No')
else:
	pat = ''.join(['?' if len(set([todel[j][p] for j in range(m)])) != 1 else todel[0][p] for p in range(len(todel[0]))])
	ok = True
	for x in w:
		if len(x) != len(pat):
			continue
		if not x in todel:
			mat = True
			for i in range(len(pat)):
				if pat[i] != '?' and pat[i] != x[i]:
					mat = False
					break
			if mat:
				ok = False
				break
	if not ok:
		print('No')
	else:
		print('Yes')
		print(pat)


[m, n] = [int(x) for x in input().split()]
strings = []
for i in range(m):
	strings.append(input())
to_delete_index = [int(x) - 1 for x in input().split()]
to_delete = [strings[int(x)] for x in to_delete_index]
base_len = len(to_delete[0])
for s in to_delete:
	if len(s) != base_len:
		print('No')
		exit()
match_string = ''
for i in range(base_len):
	match = to_delete[0][i]
	for s in to_delete:
		if s[i] != match:
			match = '?'
			break
	match_string += match

def match(s, match_string):
	if len(s) != len(match_string):
		return False
	for i in range(len(s)):
		if match_string[i] == '?':
			continue
		if match_string[i] != s[i]:
			return False
	return True
for i in range(len(strings)):
	if i in to_delete_index:
		continue
	if match(strings[i], match_string):
		print('No')
		exit()
print('Yes')
print(match_string)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
b = [int(_) for _ in input().split()]
p = list(a[b[0] - 1])
for i in range(1, len(b)):
	s = a[b[i] - 1]
	if len(s) != len(p):
		print('No')
		raise SystemExit
	for j in range(len(s)):
		if s[j] != p[j] and p[j] != '?':
			p[j] = '?'
k = 0
f = False
for i in range(n):
	if k < m and i + 1 == b[k]:
		k += 1
		continue
	s = a[i]
	if len(s) == len(p):
		f = True
		for j in range(len(s)):
			if s[j] != p[j] and p[j] != '?':
				f = False
				break
	if f:
		print('No')
		raise SystemExit
print('Yes')
print(''.join(p))


(n, m) = map(int, input().split())
l = []
for i in range(n):
	x = input()
	l.append(x)
ind = map(int, input().split())
ind = list(ind)
se = set(ind)
le = len(l[ind[0] - 1])
flag = 1
for i in range(m):
	if len(l[ind[i] - 1]) != le:
		flag = 0
		break
if flag == 1:
	s = ''
	for j in range(le):
		flagc = 1
		c = l[ind[0] - 1][j]
		for i in range(m):
			if l[ind[i] - 1][j] != c:
				flagc = 0
				break
		if flagc == 0:
			s = s + '?'
		else:
			s = s + c
	d = []
	for i in range(n):
		if i + 1 not in se:
			if len(l[i]) == le:
				d.append(l[i])
	for word in d:
		flagw = 1
		for i in range(le):
			if s[i] != '?' and s[i] != word[i]:
				flagw = 0
				break
		if flagw == 1:
			flag = 0
			break
if flag == 1:
	print('Yes')
	print(s)
else:
	print('No')


(n, m) = map(int, input().split())
a = []
b = []
for i in range(n):
	a.append(input())
t = list(map(int, input().split()))
flag = 0
x = len(a[t[0] - 1])
for i in t:
	b.append(a[i - 1])
	if len(a[i - 1]) != x:
		flag = 1
		break
s = ''
if flag != 1:
	for i in range(x):
		l = b[0][i]
		abc = 0
		for j in range(m):
			if b[j][i] != l:
				abc = 1
				break
		if abc == 0:
			s += l
		else:
			s += '?'
	for i in range(n):
		if i + 1 not in t:
			if len(a[i]) == x:
				flag = 1
				for j in range(x):
					if s[j] == '?':
						pass
					elif s[j] != a[i][j]:
						flag = 0
						break
		if flag == 1:
			break
	if flag == 1:
		print('No')
	else:
		print('Yes')
		print(s)
else:
	print('No')


(n, m) = map(int, input().split())
f = [input() for _ in range(n)]
d = set(map(int, input().split()))
c = {}
l = 0
for x in d:
	l = len(f[x - 1])
	c[l] = 1
if len(c) > 1:
	print('No')
else:
	t = ['?'] * l
	for i in range(l):
		c = {}
		ch = ''
		for x in d:
			ch = f[x - 1][i]
			c[ch] = 1
		if 1 == len(c):
			t[i] = ch
	for i in range(n):
		if i + 1 not in d:
			if len(f[i]) == l:
				ok = 0
				for j in range(l):
					if t[j] != '?' and f[i][j] != t[j]:
						ok = 1
						break
				if not ok:
					print('No')
					break
	else:
		print('Yes')
		print(''.join(t))


import sys

def scan(TYPE_1, TYPE_2=0):
	if TYPE_1 == int:
		return map(int, sys.stdin.readline().strip().split())
	elif TYPE_1 == float:
		return map(float, sys.stdin.readline().strip().split())
	elif TYPE_1 == list and TYPE_2 == float:
		return list(map(float, sys.stdin.readline().strip().split()))
	elif TYPE_1 == list and TYPE_2 == int:
		return list(map(int, sys.stdin.readline().strip().split()))
	elif TYPE_1 == str:
		return sys.stdin.readline().strip()
	else:
		print('ERROR!!!!')

def main():
	(n, m) = scan(int)
	s = []
	a = []
	for i in range(n):
		s.append(scan(str))
	x = scan(list, int)
	for i in range(m):
		a.append(s[x[i] - 1])
	l = len(a[0])
	flag = 1
	for i in range(1, m):
		if l != len(a[i]):
			flag = 0
	if flag == 0:
		print('No')
		return
	ans = ''
	for i in range(l):
		k = a[0][i]
		for j in range(1, m):
			if a[j][i] != k:
				ans += '?'
				break
		if len(ans) != i + 1:
			ans += k
	k = []
	for i in range(n):
		if len(s[i]) != l:
			continue
		flag = True
		for j in range(l):
			if s[i][j] != ans[j] and ans[j] != '?':
				flag = False
				break
		if flag:
			k.append(i + 1)
	if k == x:
		print('Yes', ans, sep='\n')
	else:
		print('No')
main()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
ini = list()
dl = list()
for i in range(n):
	s = input()
	ini.append(s)
a = list(map(int, input().split()))
ch = 1
for i in a:
	dl.append(ini[i - 1])
l = len(dl[0])
c = list(dl[0])
for i in dl:
	if len(i) != l:
		ch = 0
		break
	for j in range(l):
		if i[j] != c[j]:
			c[j] = '?'
for i in range(n):
	if i + 1 in a:
		continue
	s = ini[i]
	if len(s) != l:
		continue
	ct = 0
	for j in range(l):
		if s[j] == c[j] or c[j] == '?':
			ct += 1
	if ct == l:
		ch = 0
		break
if ch == 1:
	print('Yes')
	print(*c, sep='')
else:
	print('No')


import collections
Input = input().split()
n = int(Input[0])
m = int(Input[1])
listfile = []
for i in range(n):
	listfile.append(input())
listdet = list(map(int, input().split()))
listfile1 = []
valid = 0
for i in range(len(listdet)):
	if i == 0:
		valid = len(listfile[listdet[i] - 1])
	elif len(listfile[listdet[i] - 1]) != valid:
		valid = -1
		break
	listfile1.append(listfile[listdet[i] - 1])
result = ''
if valid == -1:
	print('No')
else:
	temp = ''
	for i in range(len(listfile1[0])):
		for j in range(len(listfile1)):
			if j == 0:
				temp = listfile1[j][i]
			if listfile1[j][i] != temp:
				result += '?'
				break
			elif j == len(listfile1) - 1:
				result += listfile1[j][i]
	count = 0
	for i in range(len(listfile)):
		if len(listfile[i]) == len(result) and i + 1 not in listdet:
			for j in range(len(listfile1[0])):
				if listfile[i][j] != result[j] and result[j] != '?':
					count += 1
					break
		elif len(listfile[i]) != len(result) and i + 1 not in listdet:
			count += 1
	if count == n - m:
		if result == '?' * len(listfile1):
			print('No')
		else:
			print('Yes')
			print(result)
	else:
		print('No')


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def solve(n, k, lst, delNum):
	m = len(lst[delNum[0] - 1])
	for i in delNum:
		if len(lst[i - 1]) != m:
			return 'No'
	common = ''
	for i in range(m):
		for j in delNum:
			if j == delNum[0]:
				common += lst[j - 1][i]
			if common[i] != lst[j - 1][i]:
				common = common[:i] + '?'
	notDelNum = []
	for i in range(1, n + 1):
		if i not in delNum:
			notDelNum.append(i)
	ques = common.count('?')
	for i in notDelNum:
		if len(lst[i - 1]) == m:
			diff = 0
			for j in range(m):
				if lst[i - 1][j] != common[j]:
					diff += 1
			if diff == ques:
				return 'No'
	print('Yes')
	return common
(n, k) = list(map(int, input().split()))
lst = []
for i in range(n):
	lst.append(input())
delNum = list(map(int, input().split()))
print(solve(n, k, lst, delNum))


n = int(input().split()[0])
all_files = [str(input()) for i in range(n)]
index_to_del = [int(i) - 1 for i in input().split()]

def find_pattern(all_files, index_to_del):
	for i in index_to_del[1:]:
		if len(all_files[i]) != len(all_files[index_to_del[0]]):
			return 'No'
	pattern = ''
	for i in range(len(all_files[index_to_del[0]])):
		added = False
		for j in index_to_del[1:]:
			if all_files[j][i] != all_files[index_to_del[0]][i]:
				if not added:
					pattern += '?'
					added = True
		if not added:
			pattern += all_files[index_to_del[0]][i]
	for i in range(len(all_files)):
		if i not in index_to_del:
			if len(all_files[i]) == len(pattern):
				matching_chars = []
				for index in range(len(pattern)):
					matching_chars.append(all_files[i][index] == pattern[index] or pattern[index] == '?')
				if all(matching_chars):
					return 'No'
	print('Yes')
	return pattern
print(find_pattern(all_files, index_to_del))


(a, b) = map(int, input().split())
k = [input() for _ in ' ' * a]
z = [i - 1 for i in map(int, input().split())]
p = set()
for i in z:
	p.add(len(k[i]))
if len(p) > 1:
	exit(print('No'))
n = list(p)[0]
s = k[z[0]]
ans = ''
for i in range(n):
	for j in range(b):
		if s[i] != k[z[j]][i]:
			ans += '?'
			break
	else:
		ans += s[i]
ok = 1
p = -1
for i in k:
	p += 1
	if p in z:
		continue
	if len(i) == n:
		ko = 1
		for j in range(n):
			if ans[j] != '?' and ans[j] != i[j]:
				ko = 0
		if ko:
			ok = 0
if ok:
	print('Yes')
	print(ans)
else:
	print('No')


l = input().split()
(n, m) = (int(l[0]), int(l[1]))
d = []
for i in range(n):
	ch = input()
	d.append(ch)
l = input().split()
l = [int(x) - 1 for x in l]
p = len(d[l[0]])
B = True
D = []
for i in l:
	if len(d[i]) == p:
		D.append(d[i])
	else:
		B = False
		break
t = []
if B:
	for i in D[0]:
		t.append(i)
	for i in range(len(D)):
		for j in range(len(D[i])):
			if D[i][j] != t[j] and t[j] != '?':
				t[j] = '?'
if B == False:
	print('No')
else:
	C = False
	for i in range(len(d)):
		if i not in l:
			C = True
		if i not in l and len(d[i]) == p:
			for j in range(len(d[i])):
				if t[j] != '?' and d[i][j] != t[j]:
					C = False
		elif i not in l and len(d[i]) != p:
			C = False
		if C == True and i not in l:
			break
	if C == False:
		print('Yes')
		for i in t:
			print(i, end='')
	else:
		print('No')