problems / 113

The Smallest Expedition Crew

medium bitmask dp 1000 ms · 256 MB

The Smallest Expedition Crew

Dr. Varga is organizing an expedition and has narrowed the roster down to n volunteers. The expedition requires s distinct named skills (things like rope rigging, cold-weather medicine, radio repair, and so on — the exact names don't matter, only which volunteers have which ones).

Each volunteer has already been assessed and has some subset of the s required skills (possibly none, possibly all of them). Dr. Varga wants to send as few volunteers as possible, while making sure that, between the volunteers who go, every one of the s required skills is covered by at least one team member. A volunteer who goes along contributes all of the skills they have, even ones nobody ends up needing twice.

Given the skill set of every volunteer, find the smallest possible expedition crew that covers all s required skills, and report who should go.

It is guaranteed that the full group of n volunteers together covers all s skills, so a valid crew always exists.

Input

The first line contains two integers n and s (1 ≤ n ≤ 60, 1 ≤ s ≤ 16) — the number of volunteers and the number of required skills.

Each of the next n lines contains a string of exactly s characters, each 0 or 1. The j-th character of the i-th string is 1 if volunteer i (1-indexed) has the j-th required skill, and 0 otherwise.

Output

Print two lines.

On the first line, print k — the minimum number of volunteers needed so that their combined skills cover all s required skills.

On the second line, print k distinct integers — the 1-indexed positions of the chosen volunteers, in any order. The union of their skills must cover all s required skills, and k must be as small as possible. If several crews of minimum size work, printing any one of them is accepted.

Notes

In the first example, volunteer 1 alone already has both required skills, so a crew of size 1 suffices.

In the second example, no single volunteer covers all three skills, but volunteers 1 and 2 together do, and no volunteer covers all three alone, so the minimum crew size is 2.

Any correct answer is accepted.

Example 1

Input

3 2
11
10
01

Output

1
1

Example 2

Input

2 3
110
011

Output

2
1 2

Hints · reveal one at a time if you're stuck

Hint 1

With only 16 skills, the set of skills covered so far can be a bitmask with at most 65536 values. Think about searching over covered-skill sets rather than over subsets of the up to 60 volunteers.

Hint 2

Run a bitmask DP: starting from nothing covered, each volunteer moves a covered set to its union with their own skills. Process the states in increasing order of mask value, and record how each state was first reached so you can print the crew.

report an issue Prefer your own editor? sooks prep 113 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.