Gig Combinatorics
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Your friend Tóti is an aspiring musician. He has written  songs, each of which has a hype rating of either , or  .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  the last song must have hype rating and all other songs must have hype rating 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  (),  the number of songs Tóti has written. The second line consists of  integers ,each in , giving the hype ratings of the .

输出描述:

Output the number of setlists Tóti can make. Since this number can be large, print it modulo .
示例1

输入

复制
9
1 1 1 2 2 2 3 3 3

输出

复制
63
示例2

输入

复制
8
1 2 1 2 3 1 2 3

输出

复制
15