Gig Combinatorics

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Your friend Tóti is an aspiring musician. He has written nn songs, each of which has a hype rating of either 11, 22, or 33. A higher hype rating means the song has more energy. Tóti is planning his first live performance and needs your help. He wants to know how many setlists he can make. A setlist consist of at least three songs, the first song must have hype rating 11, the last song must have hype rating 33, and all other songs must have hype rating 22. Tóti also wants to play the songs in the same order he wrote them.

Given the hype rating of each of Tóti's songs in the order he wrote them, how many setlists can he make?

입력

The first line of input consists of an integer nn (1n1061 \leq n \leq 10^6), the number of songs Tóti has written. The second line consists of nn integers, each in 1,2,3\\{1, 2, 3\\}, giving the hype ratings of the nn songs in the order they were written.

출력

Output the number of setlists Tóti can make. Since this number can be large, print it modulo 109+710^9 + 7.