Stickers

Time Limit:1000ms Memory Limit:64000KiB
Accepted:0 Submitted:0
Stickers

BOI 2000 Day 2 Problem 2

Stickers

Charles is an auto races fan and he has decided to make his own model's collection. In the shop it is possible to buy models in closed and covered boxes. In each box there are parts for one model and a set of stickers with images of digits. In every box the set of stickers is the same. Charles decided to label models by consecutive integers starting from 1. For example, to label the 2070-th model four stickers are necessary: one sticker with ''2'', two with ''0'' and one with ''7''.

Charles completes every model in the following way: he opens a new box, builds the model and labels it using sticker(s). He can use stickers from current and previously opened boxes, but it is not allowed to open an additional new box to get at missing stickers.

Write a program which for a given set of stickers counts how many models Charles can label in the described way.

Input

In the only line of text file STI.IN ten one-digit integers

i0, i1, i2, i3, i4, i5, i6, i7, i8, i9

are given, where ij is the number of stickers with digit j, (0<= j <= 9) in the sticker set of every box. Each two neighbour digits are separated by one space symbol.

Output

The only line of text file STI.OUT should contain one integer -- number of labeled models.

Sample Input 1

1 1 1 1 1 1 1 1 1 1

Sample Output 1

199990

Sample Input 2

3 4 5 4 3 4 5 4 3 4

Sample Output 2

49999999499999999949999999973

Remark

Time limit for each test: 20 s
SubmitStatistics

SOJ is designed and developed by Wilbur Ding and Liang Sun. ©All Rights Reserved 2009-2012.