5 * @author Iskander Akishev
7 public class funny_ia_wrong
implements Runnable
{
9 private static final String FILE_NAME
= "funny";
14 } catch (Throwable t
) {
20 private BufferedReader in
;
21 private PrintWriter out
;
23 private void solve() throws Exception
{
24 in
= new BufferedReader(new FileReader(FILE_NAME
+ ".in"));
25 out
= new PrintWriter(new File(FILE_NAME
+ ".out"));
27 StringTokenizer st
= new StringTokenizer(in
.readLine());
28 int n
= Integer
.parseInt(st
.nextToken());
29 int m
= Integer
.parseInt(st
.nextToken());
31 int[][] w
= new int[m
][26];
32 TreeSet
<String
> words
= new TreeSet
<String
>();
33 for (int i
= 0; i
< m
; i
++) {
34 String word
= in
.readLine();
36 for (char c
: word
.toCharArray()) {
42 Random rnd
= new Random();
43 for (int i
= 0; i
< 1000; i
++) {
45 for (int z
= 0; z
< 100; z
++)
46 str
+= (rnd
.nextInt(26) + 'A');
50 TreeSet
<NewWord
> newWords
= new TreeSet
<NewWord
>();
52 for (char c1
= 'A'; c1
<= 'Z'; c1
++) {
56 if (ww
[c1
- 'A'] >= 0)
60 String str
= String
.valueOf(new char[] {c1
});
61 if (!words
.contains(str
)) {
62 newWords
.add(new NewWord(str
, cnt
));
63 if (newWords
.size() > n
)
64 newWords
.remove(newWords
.last());
67 for (char c1
= 'A'; c1
<= 'Z'; c1
++) {
68 for (char c2
= 'A'; c2
<= 'Z'; c2
++) {
73 if ((ww
[c1
- 'A'] >= 0) && (ww
[c2
- 'A'] >= 0))
78 String str
= String
.valueOf(new char[] {c1
, c2
});
79 if (!words
.contains(str
)) {
80 newWords
.add(new NewWord(str
, cnt
));
81 if (newWords
.size() > n
)
82 newWords
.remove(newWords
.last());
86 for (char c1
= 'A'; c1
<= 'Z'; c1
++) {
87 for (char c2
= 'A'; c2
<= 'Z'; c2
++) {
88 for (char c3
= 'A'; c3
<= 'Z'; c3
++) {
94 if ((ww
[c1
- 'A'] >= 0) && (ww
[c2
- 'A'] >= 0) && (ww
[c3
- 'A'] >= 0))
100 String str
= String
.valueOf(new char[] {c1
, c2
, c3
});
101 if (!words
.contains(str
)) {
102 newWords
.add(new NewWord(str
, cnt
));
103 if (newWords
.size() > n
)
104 newWords
.remove(newWords
.last());
109 for (char c1
= 'A'; c1
<= 'Z'; c1
++) {
110 for (char c2
= 'A'; c2
<= 'Z'; c2
++) {
111 for (char c3
= 'A'; c3
<= 'Z'; c3
++) {
112 for (char c4
= 'A'; c4
<= 'Z'; c4
++) {
119 if ((ww
[c1
- 'A'] >= 0) && (ww
[c2
- 'A'] >= 0) && (ww
[c3
- 'A'] >= 0) && (ww
[c4
- 'A'] >= 0))
126 String str
= String
.valueOf(new char[] {c1
, c2
, c3
, c4
});
127 if (!words
.contains(str
)) {
128 newWords
.add(new NewWord(str
, cnt
));
129 if (newWords
.size() > n
)
130 newWords
.remove(newWords
.last());
136 // for (char c1 = 'A'; c1 <= 'Z'; c1++) {
137 // for (char c2 = 'A'; c2 <= 'Z'; c2++) {
138 // for (char c3 = 'A'; c3 <= 'Z'; c3++) {
139 // for (char c4 = 'A'; c4 <= 'Z'; c4++) {
140 // for (char c5 = 'A'; c5 <= 'Z'; c5++) {
142 // for (int[] ww : w) {
148 // if ((ww[c1 - 'A'] >= 0) && (ww[c2 - 'A'] >= 0) && (ww[c3 - 'A'] >= 0) && (ww[c4 - 'A'] >= 0) && (ww[c5 - 'A'] >= 0))
156 // String str = "" + c1 + c2 + c3 + c4 + c5;
157 // if (!words.contains(str)) {
158 // newWords.add(new NewWord(str, cnt));
159 // if (newWords.size() > n)
160 // newWords.remove(newWords.last());
168 for (NewWord nw
: newWords
) {
169 out
.println(nw
.word
);
180 static class NewWord
implements Comparable
<NewWord
> {
184 NewWord(String word
, int score
) {
189 public int compareTo(NewWord o
) {
190 int res
= o
.score
- score
;
192 res
= word
.compareTo(o
.word
);
198 public static void main(String
[] args
) {
199 new Thread(new funny_ia_wrong()).start();