730H.md (2615B)
1 Source: https://codeforces.com/problemset/problem/730/H 2 3 H. Delete Them 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 512 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Polycarp is a beginner programmer. He is studying how to use a command line. 22 23 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. 24 25 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. 26 27 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. 28 29 For example, the filename pattern "a?ba?": 30 31 * matches filenames "aabaa", "abba.", "a.ba9" and "a.ba."; 32 * does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.". 33 34 Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern. 35 36 Input 37 38 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. 39 40 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. 41 42 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. 43 44 Output 45 46 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. 47 48 If the required pattern doesn't exist, print the only line containing "No". 49 50 Examples 51 52 Input 53 54 ``` 55 3 2 56 ab 57 ac 58 cd 59 1 2 60 ``` 61 62 Output 63 64 ``` 65 Yes 66 a? 67 ``` 68 69 Input 70 71 ``` 72 5 3 73 test 74 tezt 75 test. 76 .est 77 tes. 78 1 4 5 79 ``` 80 81 Output 82 83 ``` 84 Yes 85 ?es? 86 ``` 87 88 Input 89 90 ``` 91 4 4 92 a 93 b 94 c 95 dd 96 1 2 3 4 97 ``` 98 99 Output 100 101 ``` 102 No 103 ``` 104 105 Input 106 107 ``` 108 6 3 109 .svn 110 .git 111 .... 112 ... 113 .. 114 . 115 1 2 3 116 ``` 117 118 Output 119 120 ``` 121 Yes 122 .??? 123 ```