#include <bits/stdc++.h>

typedef long double ld;
#define int long long

#define gcd            __gcd
#define endl           "\n"
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define pb             push_back
#define all(x)         x.begin(), x.end()
#define f              first
#define s              second
#define lb             lower_bound
#define ub             upper_bound
#define ins            insert
#define sz(x)          (int)(x).size()
#define mk             make_pair
#define deci(x, y)     fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PI             3.141592653589793238
#define mem0(x)        memset(x,0,sizeof x)
#define mem1(x)        memset(x,-1,sizeof x)
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.f << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NITIN
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

int dp[3001][3001];
int sum[3001][3001];
int last[3001][3001];
int n;
int f(int i,int j) {
    if (i == -1)
        return 0;
    if (i == n+1)
        return 1;
    if (dp[i][j] != -1)
        return dp[i][j];
    int op1=0,op2=0;
    if(last[j][i]!=n+1)
    op1 = f(last[j][i], j);
    op2 = f(last[j][i], j + 1);
    return dp[i][j]=(op1 + op2) % mod;
}
void solve() {
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;i++) {
        cin >> a[i+1];
    }
    for(int i =1;i<=n;i++) {
        int tot = 0;
        for (int j = n; j >=1; j--) {
            tot += a[j];
            tot %= i;
            sum[i][j] = tot;
        }
    }
    memset(last,-1,sizeof last);
    memset(dp,-1,sizeof dp);
    for(int i=1;i<=n;i++) {
        map<int, int> m;
        for (int j = n; j >= 1; j--) {
            if (m.count(sum[i][j])) {
                last[i][j] = m[sum[i][j]] ;
            }else if(sum[i][j]==0){
                last[i][j]=n+1;
            }
            m[sum[i][j]] = j;
        }
    }
    cout<<f(1,1)<<endl;
}

int32_t main() {
    nitin;

    solve();
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
signed main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    int m=pow(2,n);
    vector<pair<ll,int>> a(m);
    for(int i=0;i<m;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    if(n==1){ 
        if(a[0].first<a[1].first){cout<<1; return 0;}
        else{ cout<<2; return 0; }
     }
    int ans=0;
    for(int i=1;i<=n-1;i++)
    {
        vector<pair<ll,int>> b;
        for(int j=0;j<m;j+=2){
            if(a[j]>a[j+1]){ b.push_back(a[j]); }
            else{ b.push_back(a[j+1]); }
        }
        m=b.size();
        a=b;
        if(i==n-1){
            if(a[0].first<a[1].first){ ans=a[0].second; }
            else { ans=a[1].second; }
        }
    }
    cout<<ans+1;
    
    cout<<"\n";
return 0;
}