PivotOJ

Gig Combinatorics

시간 제한: 2000ms메모리 제한: 1024MB출처: NCPC 2020BOJ 21053

문제

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.

예제

예제 1

입력
9
1 1 1 2 2 2 3 3 3
출력
63

예제 2

입력
8
1 2 1 2 3 1 2 3
출력
15
코드를 제출하려면 로그인하세요.