#abc358e. E - Alphabet Tiles

E - Alphabet Tiles

Score : 475475 points

问题陈述

AtCoder Land出售写有英文字母的瓷砖。高桥正在考虑通过排列这些瓷砖来制作一个名牌。

找出满足以下条件的由大写英文字母组成的字符串的数量,长度在11KK之间(包括两端),对998244353998244353取模:

  • 对于每个满足1i261 \leq i \leq 26的整数ii,以下条件成立:
    • aia_i是按字典顺序排列的第ii个大写英文字母。例如,a1=a_1 = Aa5=a_5 = Ea26=a_{26} = Z
    • 字符串中aia_i的出现次数在00CiC_i之间(包括两端)。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

AtCoder Land sells tiles with English letters written on them. Takahashi is thinking of making a nameplate by arranging these tiles in a row.

Find the number, modulo 998244353998244353, of strings consisting of uppercase English letters with a length between 11 and KK, inclusive, that satisfy the following conditions:

  • For every integer ii satisfying 1i261 \leq i \leq 26, the following holds:
    • Let aia_i be the ii-th uppercase English letter in lexicographical order. For example, a1=a_1 = A, a5=a_5 = E, a26=a_{26} = Z.
    • The number of occurrences of aia_i in the string is between 00 and CiC_i, inclusive.

Constraints

  • 1K10001 \leq K \leq 1000
  • 0Ci10000 \leq C_i \leq 1000
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

KK

C1C_1 C2C_2 \ldots C26C_{26}

Output

Print the answer.

Sample Input 1

2
2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output 1

10

The 1010 strings that satisfy the conditions are A, B, C, AA, AB, AC, BA, BC, CA, CB.

Sample Input 2

358
1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output 2

64

Sample Input 3

1000
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000

Sample Output 3

270274035