CodeForces 407B

来源:互联网 发布:部落冲突九本升级数据 编辑:程序博客网 时间:2024/06/05 18:45
Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u
const int mod = 1000000000 + 7;#include<stdio.h>#include<iostream>using namespace std;int main(){    long long dp[1111];    int a[1111],n,i;    cin>>n;    for(i=1;i<=n;i++)    {        cin>>a[i];    }    dp[1]=0;    for(i=1;i<=n;i++)    {        dp[i+1]=(2*dp[i]-dp[a[i]]+2+mod)%mod;    }    cout<<dp[n+1]<<endl;    return 0;}

Description

One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the(n + 1)-th one.

The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room numberi(1 ≤ i ≤ n), someone can use the first portal to move from it to room number(i + 1), also someone can use the second portal to move from it to room numberpi, where1 ≤ pi ≤ i.

In order not to get lost, Vasya decided to act as follows.

  • Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room1.
  • Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to roompi), otherwise Vasya uses the first portal.

Help Vasya determine the number of times he needs to use portals to get to room(n + 1) in the end.

Input

The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line containsn integers pi (1 ≤ pi ≤ i). Eachpi denotes the number of the room, that someone can reach, if he will use the second portal in thei-th room.

Output

Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo1000000007(109 + 7).

Sample Input

Input
21 2
Output
4
Input
41 1 2 3
Output
20
Input
51 1 1 1 1
Output
62
0 0