P5950 [BalticOI 2000] Stickers

Description

Charles bought a very large number of boxes of stickers from a shop. Each sticker has one digit from $0-9$ printed on it. Each box contains the same number of stickers of each kind: $i_0$ stickers with digit $0$, $i_1$ stickers with digit $1$, …, $i_9$ stickers with digit $9$. Also, in each box, the number of stickers of each digit does not exceed $9$. At the beginning, all boxes are closed. Each time, Charles opens one new box, and then takes the stickers he needs from the boxes that have already been opened to form a number: the first time he forms $1$, the second time he forms $2$, …, and the $N$-th time he forms $N$. To form the number $N$, Charles needs to use one sticker for each digit in $N$. For example, after opening the $2070$-th box, in order to form the number $2070$, he needs to take one $2$, two $0$'s, and one $7$ from the already opened boxes (whether opened earlier or just now). The stickers taken out can be used later. If after opening a box he cannot form the corresponding number, Charles stops working. Given $i_0, i_1, i_2, …, i_9$, write a program to compute how many numbers Charles can form in total. For example, if each box contains exactly one sticker of each digit, then Charles can form $199990$ numbers in total.

Input Format

The input contains $10$ one-digit integers: $i_0, i_1, i_2, i_3, i_4, i_5, i_6, i_7, i_8, i_9$, where $i_j$ denotes the number of stickers with digit $j$ in each box.

Output Format

Output how many numbers can be formed.

Explanation/Hint

Translated by ChatGPT 5