Given an array of integers **A** of size **N** and an another array of strings **B** of size **N**. Each string in **B** is binary and of exact size **10**.

There are some Boxes having following characterstics:-

```
A[i] represents the cost of ith Box.
One Box can contain atmost 10 different colored balls in it.
B[i][j] = '1' indicates that ith Box contains jth colored ball.
B[i][j] = '0' indicates that ith Box doesn't contains jth colored ball.
```

Find and return **minimum** amount of money needed to buy the boxes such that you have **maximum distinct colored balls** in the end.

**Input Format**

```
The first argument given is the integer array A.
The second argument given is the string array B.
```

**Output Format**

```
Return minimum amount of money needed to buy the boxes such that you have maximum distinct colored balls in the end.
```

**Constraints**

```
1 <= N <= 10000
0 <= A[i] <= 10^9
B[i][j] = {'0' ,'1'}
```

**For Example**

```
Example Input 1:
A = [20, 10, 9]
B = ["0110001010", "0111110000", "1111111111"]
Example Output 1:
9
Example Explanation 1:
As box 3 contains balls of all colors, buying only this box is sufficient.
Input 2:
A = [20, 10, 9]
B = ["0110001010", "0111110001", "1111111110"]
Output 2:
19
```

NOTE:You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.

Sign Up

to access hints and editorial solutions for**BALLS IN BOXES**

to access hints and editorial solutions for

Loading...