Codeforces Global Round 21
E
Placing Jinas
Codeforces
2000
原题
← DF →
翻译中…

We say an infinite sequence $a_{0}, a_{1}, a_2, \ldots$ is non-increasing if and only if for all $i\ge 0$, $a_i \ge a_{i+1}$.

翻译中…

There is an infinite right and down grid. The upper-left cell has coordinates $(0,0)$. Rows are numbered $0$ to infinity from top to bottom, columns are numbered from $0$ to infinity from left to right.

翻译中…

There is also a non-increasing infinite sequence $a_{0}, a_{1}, a_2, \ldots$. You are given $a_0$, $a_1$, $\ldots$, $a_n$; for all $i \gt n$, $a_i=0$. For every pair of $x$, $y$, the cell with coordinates $(x,y)$ (which is located at the intersection of $x$-th row and $y$-th column) is white if $y \lt a_x$ and black otherwise.

翻译中…

Initially there is one doll named Jina on $(0,0)$. You can do the following operation.

翻译中…
  • Select one doll on $(x,y)$. Remove it and place a doll on $(x,y+1)$ and place a doll on $(x+1,y)$.
翻译中…

Note that multiple dolls can be present at a cell at the same time; in one operation, you remove only one. Your goal is to make all white cells contain $0$ dolls.

翻译中…

What's the minimum number of operations needed to achieve the goal? Print the answer modulo $10^9+7$.

翻译中…

Input

翻译中…

The first line of input contains one integer $n$ ($1\le n\le 2\cdot 10^5$).

翻译中…

The second line of input contains $n+1$ integers $a_0,a_1,\ldots,a_n$ ($0\le a_i\le 2\cdot 10^5$).

翻译中…

It is guaranteed that the sequence $a$ is non-increasing.

翻译中…

Output

翻译中…

Print one integer — the answer to the problem, modulo $10^9+7$.

翻译中…

Note

翻译中…

Consider the first example. In the given grid, cells $(0,0),(0,1),(1,0),(1,1)$ are white, and all other cells are black. Let us use triples to describe the grid: triple $(x,y,z)$ means that there are $z$ dolls placed on cell $(x,y)$. Initially the state of the grid is $(0,0,1)$.

翻译中…

One of the optimal sequence of operations is as follows:

翻译中…
  • Do the operation with $(0,0)$. Now the state of the grid is $(1,0,1),(0,1,1)$.
  • Do the operation with $(0,1)$. Now the state of the grid is $(1,0,1),(1,1,1),(0,2,1)$.
  • Do the operation with $(1,0)$. Now the state of the grid is $(1,1,2),(0,2,1),(2,0,1)$.
  • Do the operation with $(1,1)$. Now the state of the grid is $(1,1,1),(0,2,1),(2,0,1),(1,2,1),(2,1,1)$.
  • Do the operation with $(1,1)$. Now the state of the grid is $(0,2,1),(2,0,1),(1,2,2),(2,1,2)$.
翻译中…

Now all white cells contain $0$ dolls, so we have achieved the goal with $5$ operations.

翻译中…

样例

Input #1
2
2 2 0
Output #1
5
InputCopy OutputCopy
Input #2
10
12 11 8 8 6 6 6 5 3 2 1
Output #2
2596
InputCopy OutputCopy
题目信息
题号
1696E
时间限制
2 s
内存限制
512 MB
标签
组合数学
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。