Digits - MarisaOJ: Marisa Online Judge

Digits

Time limit: 1000 ms
Memory limit: 256 MB
You have various cards labeled with digits from $0$ to $9$. You have $a_i$ cards labeled with the digit $i$. You use these cards to form consecutive integers starting from the positive integer $n$ until you no longer have enough cards to form the next integer. How many cards can you form? ### Input - The first line contains a positive integer $n$. - The second line consists of 10 non-negative integers $a_0, a_1, ..., a_9$ where $(a_i \le 10^{11})$. ### Output - Print an integer representing the number of cards you can form. ### Constraints - 40% of tests have $a_i \le 1000$. - 60% of the remaining tests have no additional constraints. ### Example Input: ``` 12 0 4 2 1 1 1 3 0 0 0 ``` Output: ``` 4 ```