시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB72545176.119%

문제

Your friend Tóti is an aspiring musician. He has written $n$ songs, each of which has a hype rating of either $1$, $2$, or $3$. 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 $1$, the last song must have hype rating $3$, and all other songs must have hype rating $2$. 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 $n$ ($1 \leq n \leq 10^6$), the number of songs Tóti has written. The second line consists of $n$ integers, each in $\{1, 2, 3\}$, giving the hype ratings of the $n$ 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 $10^9 + 7$.

예제 입력 1

9
1 1 1 2 2 2 3 3 3

예제 출력 1

63

예제 입력 2

8
1 2 1 2 3 1 2 3

예제 출력 2

15

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2020 G번

Camp > Petrozavodsk Programming Camp > Winter 2021 > Day 3: Nordic+ Contest 2020 G번

  • 문제를 만든 사람: Bergur Snorrason, Eyleifur Ingþór Bjarkason