long s,a[101];i,t,k=101;main(j){for(gets(&t);~scanf("%d",&t)?++a[t]:i--?s+=a[i]*a[j]*a[k],1:(i=--j)?:(j=--k););s=!printf("%d",s%=i=1e9+7);}