beecrowd | 2513

Xoringan

By Francisco Elio Parente Arcos Filho, UEA BR Brazil

Timelimit: 4

Members of Uxorra clan inhabiting the prestigious Leaf Village are prominent ninjas whose skills are envied by many. In addition to its excellent strength and jutsu (ninja techniques) with fire, they have an asset that highlights even more the other ninjas of the village and the world: Their Xoringan.

The Xoringan is a dojutsu (eyes with ninja skills) kekkei genkai (skill transferred through bloodline) very powerful and used by clan members generally in battles. It gives the user a lot of useful skills during a fight, like be able to see the flow of chakra's enemy (used internal energy to do jutsus),predict the movements of the opponent and even copy techniques by looking at them once.

The jutsu are made with a specific combination of seals (gestures with hands joined and positioning of the fingers) where each seal can only be used once in a jutsu. Some seals are more powerful and when used in a jutsu, they give you the power of greater attack, others, not so much. There are 64 different types of seals, being 1 the weakest attack power, the second weakest has twice the first, third weakest has twice the second and so on. This makes each different jutsu to have a single attack power and can be seen by a Xoringan user as a number. For example, a jutsu that uses the first, third and fifth seals has an attack power of 21 and may simply be referred to as jutsu 21.

There are skilled ninjas that can do secret jutsus as they perform other and reuse seals that were used in these jutsus. For example, if the ninja performs a sequence of techniques, he can reuse each combination of seals used to make each jutsus to do the combination of the secret jutsu seals. To find out what is the secret jutsu you need to know which seals, including all used in sequence, remain active. When a seal is made for the first time it is activated, but if is made a second time then it is disabled and can be activated again if it is done again in another jutsu in sequence.

For example, if a ninja do the jutsus 10, 31, 21, 15, 14, 7, 5 and 9 and try to do the secret jutsu using the seals between the third and seventh (21, 15, 14, 7, 5), the secret jutsu that will be done is 22. It is also important to note that not every jutsu is so secret. If in the same sequence he tried to do the secret jutsu only during the first jutsu, it just would eventually make the jutsu 10 again.

Rodrigo is a young Uxorra using his Xoringan to be able to predict all the jutsus that your opponent will do and in the exact order is therefore able to measure the threat that your opponent is. And this is nothing more than the sum of the attack power of all possible secret jutsus that your opponent has the ability to do.

Your task is to make a program that simulates the powers of Xoringan and can say, given the jutsu's sequence that ninja will do, the threat it represents.

Input

The input consists of several test cases. The first line of a test case contains an integer N (1 ≤ N ≤ 103) representing the amount of jutsu provided for Xoringan. The second line contains N integers in the order of execution representing the attack power of each jutsu.

Output

The output consists of a line per test case representing the value of threat that a jutsu's sequence represents modulo 109+7.

Input Sample Output Sample

2

2 3

2

3 7

3

1 2 3

6

14

10