program P2099;
const
mo=1000000007;
var
i,n:longint;
cnt:array[1..2] of longint;
pres,dp:array[1..2] of int64;
a:array[1..100010] of integer;
ans:int64;
procedure inc0(var u:int64;v:int64);
begin
u:=(u+v) mod mo;
end;
begin
assign(input,'asm_code.in');assign(output,'asm_code.out');
reset(input);rewrite(output);
readln(n);
for i:=1 to n do
read(a[i]);
for i:=1 to n do
begin
ans:=(ans+dp[a[i]]) mod mo;
inc0(pres[a[i]],cnt[3-a[i]]);
inc(cnt[a[i]]);
inc0(dp[3-a[i]],pres[3-a[i]]);
end;
writeln(ans);
close(input);close(output);
end.