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
#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;

void inc_enter(int &a)
{
    int tp;

    scanf("%d", &tp);

    a += tp;
    if(a >= mod)
        a -= mod;
}

struct tree
{
    struct node
    {
        int val;
        node *l, *r;

        node(int val, node* l, node *r) : val(val), l(l), r(r) {}
    };

    int get_val(node *v)
    {
        return v ? v->val : 0;
    }

    int N = 1, sum = 0;
    node *root = new node(0, NULL, NULL);

    void upf(node *v, int l, int r, int &key, int &val)
    {
        if(l == r)
        {
            //cout << v->val << ":\n";
            v->val += val;
            if(v->val >= mod)
                v->val -= mod;

            //cout << l << " " << r << ": " << val << " " << v->val <<endl;
        }
        else
        {
            int mid = (l + r) >> 1;

            if(key <= mid)
            {
                if(!v->l)
                    v->l = new node(0, NULL, NULL);
                upf(v->l, l, mid, key, val);
            }
            else
            {
                if(!v->r)
                    v->r = new node(0, NULL, NULL);
                upf(v->r, mid + 1, r, key, val);
            }

            v->val = get_val(v->l) + get_val(v->r);
            if(v->val >= mod)
                v->val -= mod;
        }
    }

    int quf(node *v, int l, int r, int &lim)
    {
        if(!v || l > lim)
            return 0;

        if(r <= lim)
        {
            //cout << l << " " << r << " " << v->val << endl;
            return v->val;
        }

        int mid = (l + r) >> 1;

        int ret = quf(v->l, l, mid, lim) + quf(v->r, mid + 1, r, lim);
        if(ret >= mod)
            ret -= mod;

        return ret;
    }

    void insert(int key, int val)
    {
        while(N <= key)
        {
            root = new node(root->val, root, NULL);

            N <<= 1;
        }

        upf(root, 0, N - 1, key, val);
        sum += val;
        if(sum >= mod)
            sum -= mod;
    }

    int lower_equal_sum(int lim)
    {
        return quf(root, 0, N - 1, lim);
    }

    int higher_sum(int lim)
    {
        int ret = sum - lower_equal_sum(lim);
        if(ret < 0)
            ret += mod;

        return ret;
    }
};

int n;
tree dp[2];

int main()
{
    scanf("%d", &n);

    dp[0].insert(0, 1);

    int csum = 0;
    for(int i = 1; i < n; i++)
    {
        inc_enter(csum);

        int add = dp[csum & 1].lower_equal_sum(csum) + dp[(csum & 1) ^ 1].higher_sum(csum);
        if(add >= mod)
            add -= mod;

        dp[csum & 1].insert(csum, add);
    }

    inc_enter(csum);

    int res = dp[csum & 1].lower_equal_sum(csum) + dp[(csum & 1) ^ 1].higher_sum(csum);
    if(res >= mod)
        res -= mod;

    printf("%d", res);
}