#P5950. [BalticOI 2000] Stickers

[BalticOI 2000] Stickers

Description

Charles bought a very large number of boxes of stickers from a shop. Each sticker has one digit from 090-9 printed on it.

Each box contains the same number of stickers of each kind: i0i_0 stickers with digit 00, i1i_1 stickers with digit 11, …, i9i_9 stickers with digit 99. Also, in each box, the number of stickers of each digit does not exceed 99.

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 11, the second time he forms 22, …, and the NN-th time he forms NN. To form the number NN, Charles needs to use one sticker for each digit in NN.

For example, after opening the 20702070-th box, in order to form the number 20702070, he needs to take one 22, two 00's, and one 77 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 i0,i1,i2,,i9i_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 199990199990 numbers in total.

Input Format

The input contains 1010 one-digit integers: i0,i1,i2,i3,i4,i5,i6,i7,i8,i9i_0, i_1, i_2, i_3, i_4, i_5, i_6, i_7, i_8, i_9, where iji_j denotes the number of stickers with digit jj in each box.

Output Format

Output how many numbers can be formed.

3 4 5 4 3 4 5 4 3 4
49999999499999999949999999973

Hint

Translated by ChatGPT 5