402196: GYM100694 F The Berland Championship

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. The Berland Championshiptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Every year BerSU (Berland State University) holds the programming contest «The Berland Championship». This year Andrey, the student of BSAU (Berland State Alternative University), helped to prepare the problems. There were m problems prepared in total.

Andrey is proud of his university very much so he wants the BSAU team to win. Of course, he isn't allowed to share the problems with BSAU teams, but he can give advice how to form the teams.

n BSAU students want to take part in the competition. For each student, Andrey knows what problems he can solve, and also what is his productivity — the maximum number of problems he can solve during the contest. Every team must consist of three students. Andrey believes that BSAU students will act optimally at the contest, that is, everyone will solve the maximal number of problems he can. However, no student will solve more problems than his productivity, and no team will solve problems that aren't solvable by its students.

Help Andrey to form exactly one team of three students so it could solve the maximal number of problems comparing to all other possible BSAU teams.

Input

The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 1000) — the number of BSAU students and the number of problems.

The second line contains n integers pi (0 ≤ pi ≤ m) — the productivities of the students.

Each of the next n lines contains a string of uppercase and lowercase Latin letters namei (|namei| ≤ 10) — the name of the i-th student. All names are pairwise distinct.

Then the binary matrix a of size n × m follows. Its rows correspond to students, and columns — to problems. If ai, j is 1, i-th student can solve j-th problem, otherwise he can't.

Output

In the first line output a single integer s — the maximal number of problems the team formed by Andrey can solve.

In the second line output the names of the students in this team. The names can be written in any order.

If there are several optimal solutions, output any of them.

ExamplesInput
5 5
3 2 2 3 1
Slava
Andrew
Egor
Denis
Sergey
11011
10100
00001
00100
10000
Output
5
Slava Andrew Egor
Input
4 6
1 2 1 2
Denis
Andrew
Egor
Slava
100011
111100
000101
000111
Output
5
Denis Andrew Slava

加入题单

算法标签: