Secure PIN System Design#4901

Secure PIN System Design

1 second
64 megabytes
Hard

Global Security Systems Inc. is developing a new authentication system for high-security applications. The security team has identified that traditional PIN codes are vulnerable when users choose patterns with excessive consecutive digit repetitions (like 1111, 2222, or 000).

To enhance security, the team is designing a new PIN validation system with the following requirements:

For example, if t_1 = 2, then the PIN "11234" would be valid, but "11123" would be invalid if it contained three consecutive 1s anywhere.

The security analysts need to determine: Given the PIN length and the consecutive repetition limits t_k for each digit , how many valid PINs can be generated under these security constraints?

This analysis helps the security team:

Input

The first line contains the PIN length (1 \leq n \leq 9).

The second line contains ten integers: t_0, t_1, …, t_9 (0 \leq t_k \leq 9), representing the maximum number of consecutive occurrences allowed for each digit.

Output

Output a single integer representing the total number of valid PINs that satisfy all security constraints.

Examples

Example 1

Loading
Loading