1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
///MEMENTO MEMO, MEMENTO LONG LONG
#include <bits/stdc++.h>

#define DEBUG if(0)
#define COUT cout << "\e[36m"
#define ENDL "\e[39m" << endl
#define VAR(v) " [\e[32m" << #v << "\e[36m=\e[91m" << v << "\e[36m] "

using namespace std;

typedef long long LL;

const LL P = 1e9+7;

int n;
vector<LL> nums;

vector<int> pref;

struct SegTree
{
    vector<int> v;

    int query(int b, int e)
    {
        int ret = 0;
        for (int i = b; i <= e; ++i)
        {
            ret = (ret + v[i])%P;
        }
        return ret;
    }

    void add(int a, int val)
    {
        v[a] += val;
        v[a] %= P;
    }

    SegTree(int size)
    {
        v.resize(size);
    }
};


struct Solver
{
    virtual int get_poss(int ix) = 0;

    virtual void update(int ix, int val) = 0;

    virtual ~Solver() =default;
};


//struct MagicSolver : Solver
//{
//    array<SegTree, 2> trees = {SegTree(P), SegTree(P)};
////    SegTree trees[2] = {SegTree(P), SegTree(P)};
//
//    int get_poss(int ix) override
//    {
//        LL poss = 0;
//        return poss%P;
//    }
//
//    void update(int ix, int val) override
//    {
//        int tree_ix = pref[ix]; //TO DO
//
//        trees[pref[ix]%2].add(tree_ix, val);
//
//    }
//};


struct SquareSolver : Solver
{
    vector<int> dp = vector<int>(n);
//    SegTree trees[2] = {SegTree(P), SegTree(P)};

    int get_poss(int ix) override
    {
        LL sum = nums[ix];
        for(int j = ix-1; j >= 0; j--)
        {
            if(sum%2 == 0)
            {
                dp[ix] += dp[j];
                dp[ix] %= P;
            }
            sum = (sum+nums[j])%P;
        }
        if(sum%2 == 0)
        {
            dp[ix] ++;
            dp[ix] %= P;
        }
        return dp[ix];
    }

    void update(int ix, int val) override
    {
        return;

    }
};

struct SmallSolver : Solver
{
    vector<vector<int>> dp;
//    SegTree trees[2] = {SegTree(P), SegTree(P)};

    SmallSolver()
    {
        dp.resize(2);
        for(auto& el : dp)
        {
            el.resize(2);
        }
        //dp[ix][parity];
        dp[1][0] = 1;
    }


    int get_poss(int ix) override
    {
        dp[ix%2][0] = ((nums[ix]%2 == 0)?
                       ((ix>0)? 2 : 1)*dp[(ix+1)%2][0] :
                dp[(ix+1)%2][1]);
        dp[ix%2][1] = ((nums[ix]%2 == 0)?
                       dp[(ix+1)%2][1] :
                       ((ix>0)? 2 : 1)*dp[(ix+1)%2][0]);

        dp[ix%2][0] %= P;
        dp[ix%2][1] %= P;


        DEBUG COUT << ix << ": [" << dp[ix%2][0] << "][" << dp[ix%2][1] << " ";
        return dp[ix%2][0];
    }

    void update(int ix, int val) override
    {
        return;

    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    nums.resize(n);
    pref.resize(n);
    DEBUG COUT << VAR(n) << ENDL;
    for (int i = 0; i < n; ++i)
    {
        cin >> nums[i];
        pref[i] += nums[i];
        DEBUG COUT << VAR(nums[i]) << ENDL;
        pref[i] += (i > 0)? pref[i-1] : 0;
    }
    Solver* sol;// = new SmallSolver;
    if(n <= 3000)
    {
        sol = new SquareSolver;
    }
    else
    {
        sol = new SmallSolver;
    }

    int poss = 0;
    for (int i = 0; i < n; ++i)
    {
        //get poss
        poss = sol->get_poss(i);
        DEBUG COUT << VAR(poss);
        //update tree
        sol->update(i, poss);

    }

    DEBUG COUT << ENDL;
    cout << poss << "\n";
    delete sol;
}