Under construction

Still being built. Things may change

Alien Microwave

Time limit1sMemory limit1024 MB

Summary
Count the valid cooking times that become invalid when exactly one digit is dropped, where each two-digit part a_i must be less than t_i.
Level

Medium7 of 10

Topics
Combinatorics, Math
Solved
No attempts yet

Problem

A standard microwave takes the cooking time as a string in the form hhmmss, where hh, mm, and ss are two-digit integers less than 24, 60, and 60, respectively. Leading zeros in hhmmss are omitted. For example, 3 minutes is entered as 300, though 0300 or 00300 is also accepted.

If any of hh, mm, or ss exceeds its limit, the microwave rejects the input and gives an error. For example, 75 and 240000 are not accepted. In this problem, zero seconds of cooking time (written as one or more 0s) is also a valid cooking time.

When entering a time, a user may accidentally omit one digit. For example, entering 1030 (10 minutes and 30 seconds) becomes 100 (1 minute) if the digit 3 is omitted, and 030 (30 seconds) if the digit 1 is omitted. Omitting any of the four digits still gives a valid cooking time. However, 1700 (17 minutes) becomes invalid if either of the zeros is omitted. A valid cooking time that becomes invalid when exactly one digit is omitted is called an Error-Prone cooking time.

On an alien planet, a standard microwave is operated by a string a1a2a3…ana_1a_2a_3 \dots a_n, where each aia_i is a two-digit non-negative integer in base 10 that is less than tit_i. The rules for valid and invalid cooking times still apply.

Given the limits t1,t2,…,tnt_1, t_2, \dots, t_n, find the number of Error-Prone cooking times. Leading zeros do not change a cooking time, so 066 and 66 are the same time and are counted once. Also, 0 is a valid cooking time.

Input

The first line contains an integer nn (1≤n≤91 \le n \le 9), the number of time types in the alien time scheme.

Each of the next nn lines contains an integer tit_i (1≤ti≤1001 \le t_i \le 100), the number of partitions in the iith time type.

Output

Print a single integer: the number of Error-Prone cooking times, counting each time once regardless of leading zeros.

Examples1

  1. Example 1

    Input
    3
    24
    60
    60
    
    Expected output
    51840