#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define pb push_back
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005
const int mod = 1e9 + 7;
int n;
int a[MAXX];
signed main()
{
_FastIO;
cin >> n;
int ans = 1;
for(int i = 0; i < n; i++){
cin >> a[i];
ans *= a[i];
ans %= mod;
}
if(a[0] == 1 || a[n - 1] == 1){
ans++;
}
ans %= mod;
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKI2RlZmluZSBpbnQgbGwKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBfRmFzdElPIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7IGNvdXQudGllKDApCiNkZWZpbmUgTUFYWCAxMDAwMDUKY29uc3QgaW50IG1vZCA9IDFlOSArIDc7CgppbnQgbjsKaW50IGFbTUFYWF07CgpzaWduZWQgbWFpbigpCnsKCV9GYXN0SU87CgljaW4gPj4gbjsKCWludCBhbnMgPSAxOwoJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CgkJY2luID4+IGFbaV07CgkJYW5zICo9IGFbaV07CgkJYW5zICU9IG1vZDsKCX0KCWlmKGFbMF0gPT0gMSB8fCBhW24gLSAxXSA9PSAxKXsKCQlhbnMrKzsgCgl9CglhbnMgJT0gbW9kOwoJY291dCA8PCBhbnMgPDwgZW5kbDsKCXJldHVybiAwOwp9