#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    lli i,j,n,start=0,item,index,flag=1,sz=0;
    cin>>n;
    vector <lli> q(n-1);
    for(i=0;i<n-1;i++)
        cin>>q[i];
    while(start<=n)
    {
        sz=0;
        flag=1;
        start++;
        item = start;
        //starting with start=1
        //vector <lli> p;
      //  p.push_back(start);
        for(j=0;j<n-1;j++)
        {
            item += q[j];
          //  cout<<item<<" ";
                       //item  =  p[i+1]
            if(item<=0)
                break;          //this iteration is wasted
            else if(item>n)
            {
                cout<<-1;
                return 0;
            }
            sz++;
           // p.push_back(item);
        }
        //cout<<"\t"<<sz<<"\n";
        if(sz==n-1)        //means the vector p is full
        {
            vector <lli> f(n+1);
            for(j=0;j<n;j++)
            {
                if(j==0)
                    index = start;
                else
                    index += q[j-1];
              //  cout<<index<<" ";
                f[index]++;
                if(f[index]>1)
                {
                    flag=0;
                    break;
                }
            }
            //cout<<endl;
            if(flag==1)
            {
                //cout<<"hi";
                for(j=0;j<n;j++)
                {
                    if(j==0)
                        index = start;
                    else
                        index += q[j-1];
                    cout<<index<<" ";
                }
                return 0;
            }
        }
    }
    cout<<-1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    lli i,j,n,start=1,item,index,flag=1,sz=0,sum=0,mini=0;
    cin>>n;
    vector <lli> q(n-1);
    for(i=0;i<n-1;i++)
    {
        cin>>q[i];
        sum+=q[i];
        if(mini > sum)
            mini = sum;
    }
    start = i-mini;
    else if(sum>n-1)
    {
        cout<<-1;
        return 0;

    }
    while(start<=n)
    {
        sz=0;
        flag=1;
        item = start;
        for(j=0;j<n-1;j++)
        {
            item += q[j];
            if(item<=0)
                break;
            else if(item>n)
            {
                cout<<-1;
                return 0;
            }
            sz++;
        }
        if(sz==n-1)
        {
            vector <lli> f(n+1);
            for(j=0;j<n;j++)
            {
                if(j==0)
                    index = start;
                else
                    index += q[j-1];
                f[index]++;
                if(f[index]>1)
                {
                    cout<<-1;
                    return 0;
                }
            }

            for(j=0;j<n;j++)
            {
                if(j==0)
                    index = start;
                else
                    index += q[j-1];
                cout<<index<<" ";
            }
            return 0;
        }
        start++;
    }
    cout<<-1;
    return 0;
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            mini=min(mini,p[j]);
        }
    }
    bool b=true;
    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        p[i]=p[i]-(mini)+1;
        cnt[p[i]-1]++;
        if(p[i]>n || cnt[p[i]-1]>1){
            cout<<-1;
            b=false;
            break;
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            mini=min(mini,p[j]);
        }
    }
    bool b=true;
    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        p[i]=p[i]-(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
            break;
        }
        else{
            cnt[p[i]-1]++;
            if(cnt[p[i]]>1){
                b=false;
                cout<<-1;
                break;
            }
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            if(i==n-2){
                mini=min(mini,p[i]);
            }
        }
    }
    bool b=true;
    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        p[i]=p[i]-(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
            break;
        }
        else{
            cnt[p[i]-1]++;
            if(cnt[p[i]-1]>1){
                b=false;
                cout<<-1;
                break;
            }
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            //mini=min(mini,p[j]);
        }
    }
    for(int i=0;i<n;i++){
        mini=min(mini,p[i]);
    }
    bool b=true;
    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        p[i]=p[i]-(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
            break;
        }
        else{
            cnt[p[i]-1]++;
            if(cnt[p[i]-1]>1){
                b=false;
                cout<<-1;
                break;
            }
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            mini=min(mini,p[j]);
        }
    }
    bool b=true;
    for(int i=0;i<n;i++){
        p[i]=p[i]+abs(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        cin>>p[i];
    }
    for(int i=n-2;i>=0;i--){
        p[i]=-p[i]+p[i+1];
        mini=min(mini,p[i]);
    }
    bool b=true;
    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        p[i]=p[i]-(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
            break;
        }
        else{
            cnt[p[i]-1]++;
            if(cnt[p[i]-1]>1){
                b=false;
                cout<<-1;
                break;
            }
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            if(i==n-2){
                mini=min(mini,p[j]);
            }
        }
    }
    bool b=true;
    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        p[i]=p[i]-(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
            break;
        }
        else{
            cnt[p[i]-1]++;
            if(cnt[p[i]-1]>1){
                b=false;
                cout<<-1;
                break;
            }
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll mini=0;
    cin>>n;
    vector<ll> p(n,0);
    for(int i=1;i<n;i++){
        cin>>p[i];
        p[i]+=p[i-1];
        mini=min(mini,p[i]);
    }
    vector<int> a(n+1,0);
    for(int i=0;i<n;i++){
        p[i]-=(mini-1);
        if(p[i]>n){
            cout<<-1;
            return 0;
        }
        else{
            a[p[i]]++;
            if(a[p[i]]>1){
                cout<<-1;
                return 0;
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<p[i]<<" ";

}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=INT_MAX;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            mini=min(mini,p[j]);
        }
    }
    bool b=true;
    for(int i=0;i<n;i++){
        p[i]=p[i]+abs(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
    //cout<<mini;
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            mini=min(mini,p[j]);
        }
    }
    bool b=true;
    for(int i=0;i<n;i++){
        p[i]=p[i]-(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
            break;
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#include<bits/stdc++.h>
#include <iterator>
using namespace std;
#define ll long long
#define M 1000000007LL
#define sz(a) (ll)a.size()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll>
#define MAXN 200002

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> q(n-1);
    for(int i=0;i<n-1;i++)
        cin>>q[i];
    vector<int> p(n,0);
    int mini=0;
    for(int i=0;i<n-1;i++){
        for(int j=i;j>=0;j--){
            p[j]-=q[i];
            mini=min(mini,p[j]);
        }
    }
    bool b=true;
    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        p[i]=p[i]-(mini)+1;
        if(p[i]>n){
            cout<<-1;
            b=false;
            break;
        }
        else{
            cnt[p[i]-1]++;
            if(cnt[p[i]-1]>1){
                b=false;
                cout<<-1;
                break;
            }
        }
    }
    if(b==true){
        for(int i=0;i<n;i++)
            cout<<p[i]<< " ";
    }
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>

#define pii			std::pair<int,int>
#define ll			long long
#define _2ll			(long long)

std::vector<int> v ;

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

	int sum = 0 , m = 0 ;

	for ( int i = 0 ; i < n - 1 ; i++ ) {
		int tmp ;
		scanf ( "%d" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
	}

	int p = - ( m - 1 ) ;

	v.push_back ( 0 ) ;

	for ( int j = 0 ; j < n ; j++ ) {
		printf ( "%d " , p ) ;
		p += v [ j ] ;
	}

	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

std::vector<int> v ;
std::vector<int> a ;

int main ( void ) {
	long long n ;
	scanf ( "%lld" , &n ) ;
	long long sum = 0 , m = 0 ;
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		int tmp ;
		scanf ( "%d" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
	}
	int p = - ( m - 1 ) ;
	v.push_back ( 0 ) ;
	sum = 0 ;
	for ( int j = 0 ; j < n ; j++ ) {
		sum += p ;
		a.push_back ( p ) ;
		p += v [ j ] ;
	}
	if ( sum * 2ll == ( long long ) ( n ) * ( long long ) ( n + 1 ) )
		for ( auto p : a ) printf ( "%d " , p ) ;
	else printf ( "-1" ) ;
	printf ( "\n" ) ;
	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

std::vector<int> v ;
std::vector<int> a , b ;
std::vector<int> p ;

int main ( void ) {
	long long n ;
	scanf ( "%lld" , &n ) ;
	long long sum = 0 , m = 0 ;
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		long long tmp ;
		scanf ( "%lld" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
		p.push_back ( i + 1 ) ;
	}
	long long p0 = 1 - m ;
	for ( int i = 0 ; i < n ; i++ ) {
		a.push_back ( p0 ) ;
		b.push_back ( p0 ) ;
		p0 += v [ i ] ;
	}
	std::sort ( b.begin ( ) , b.end ( ) ) ;
	for ( int i = 0 ; i < n ; i++ )
		if ( b [ i ] != p [ i ] ) {
			printf ( "-1\n" ) ;
			return 0 ;
		}
	for ( int i = 0 ; i < n ; i++ )
		printf ( "%d " , a [ i ] ) ;
	printf ( "\n" ) ;
	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

std::vector<int> v ;
std::vector<int> a ;

int main ( void ) {
	int n ;
	scanf ( "%d" , &n ) ;
	long long sum = 0 , m = 0 ;
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		int tmp ;
		scanf ( "%d" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
	}
	int p = - ( m - 1 ) ;
	v.push_back ( 0 ) ;
	sum = 0 ;
	for ( int j = 0 ; j < n ; j++ ) {
		sum += p ;
		a.push_back ( p ) ;
		p += v [ j ] ;
	}
	if ( sum * 2ll == ( long long ) ( n ) * ( long long ) ( n + 1 ) )
		for ( auto p : a ) printf ( "%d " , p ) ;
	else printf ( "-1" ) ;
	printf ( "\n" ) ;
	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

std::vector<long long> v ;
std::vector<long long> a ;

int main ( void ) {
	long long n ;
	scanf ( "%lld" , &n ) ;
	long long sum = 0 , m = 0 ;
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		long long tmp ;
		scanf ( "%lld" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
	}
	long long p = - ( m - 1 ) ;
	v.push_back ( 0 ) ;
	sum = 0 ;
	long long check_sum2 = ( ( long long ) ( n ) ) * ( ( long long ) ( n + 1 ) ) ;
	for ( int j = 0 ; j < n ; j++ ) {
		sum += p ;
		a.push_back ( p ) ;
		p += v [ j ] ;
	}
	if ( sum * 2ll == check_sum2 )
		for ( auto p : a )
			printf ( "%lld " , p ) ;
	else printf ( "-1" ) ;
	printf ( "\n" ) ;
	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

std::vector<int> v ;
std::vector<int> a , b ;
std::vector<int> p ;

int main ( void ) {
	long long n ;
	scanf ( "%lld" , &n ) ;
	long long sum = 0 , m = 0 ;
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		long long tmp ;
		scanf ( "%lld" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
		p.push_back ( i + 1 ) ;
	}
	long long p0 = 1 - m ;
	v.push_back ( 0 ) ;
	for ( int i = 0 ; i < n ; i++ ) {
		a.push_back ( p0 ) ;
		b.push_back ( p0 ) ;
		p0 += v [ i ] ;
	}
	std::sort ( b.begin ( ) , b.end ( ) ) ;
	for ( int i = 0 ; i < n ; i++ )
		if ( b [ i ] != p [ i ] ) {
			printf ( "-1\n" ) ;
			return 0 ;
		}
	for ( int i = 0 ; i < n ; i++ )
		printf ( "%d " , a [ i ] ) ;
	printf ( "\n" ) ;
	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

std::vector<int> v ;
std::vector<int> a , b ;
std::vector<int> p ;

int main ( void ) {
	long long n ;
	scanf ( "%lld" , &n ) ;
	long long sum = 0 , m = 0 ;
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		long long tmp ;
		scanf ( "%lld" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
		p.push_back ( i + 1 ) ;
	}
	p.push_back ( n ) ;
	long long p0 = 1 - m ;
	v.push_back ( 0 ) ;
	for ( int i = 0 ; i < n ; i++ ) {
		a.push_back ( p0 ) ;
		b.push_back ( p0 ) ;
		p0 += v [ i ] ;
	}
	std::sort ( b.begin ( ) , b.end ( ) ) ;
	for ( int i = 0 ; i < n ; i++ ) {
		if ( b [ i ] != p [ i ] ) {
			printf ( "-1\n" ) ;
			return 0 ;
		}
	}
	for ( int i = 0 ; i < n ; i++ )
		printf ( "%d " , a [ i ] ) ;
	printf ( "\n" ) ;
	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>

#define pii			std::pair<int,int>
#define ll			long long
#define _2ll			(long long)

std::vector<int> v ;
std::vector<int> a ;

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

	int sum = 0 , m = 0 ;

	for ( int i = 0 ; i < n - 1 ; i++ ) {
		int tmp ;
		scanf ( "%d" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
	}

	int p = - ( m - 1 ) ;

	v.push_back ( 0 ) ;

	sum = 0 ;

	for ( int j = 0 ; j < n ; j++ ) {
		sum += p ;
		a.push_back ( p ) ;
		p += v [ j ] ;
	}

	if ( 2 * sum == n * ( n + 1 ) )
		for ( auto p : a ) printf ( "%d " , p ) ;
	else printf ( "-1" ) ;

	printf ( "\n" ) ;

	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

std::vector<long long> v ;
std::vector<long long> a ;

int main ( void ) {
	long long n ;
	scanf ( "%lld" , &n ) ;
	long long sum = 0 , m = 0 ;
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		int tmp ;
		scanf ( "%d" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
	}
	long long p = - ( m - 1 ) ;
	v.push_back ( 0 ) ;
	sum = 0 ;
	long long check_sum2 = ( ( long long ) ( n ) ) * ( ( long long ) ( n + 1 ) ) ;
	for ( int j = 0 ; j < n ; j++ ) {
		sum += p ;
		a.push_back ( p ) ;
		p += v [ j ] ;
	}
	if ( sum * 2ll == check_sum2 )
		for ( auto p : a )
			printf ( "%lld " , p ) ;
	else printf ( "-1" ) ;
	printf ( "\n" ) ;
	return 0 ;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

std::vector<int> v ;
std::vector<int> a , b ;
std::vector<int> p ;

int main ( void ) {
	long long n ;
	scanf ( "%lld" , &n ) ;
	long long sum = 0 , m = 0 ;
	for ( int i = 0 ; i < n - 1 ; i++ ) {
		long long tmp ;
		scanf ( "%lld" , &tmp ) ;
		sum += tmp ;
		m = std::min ( m , sum ) ;
		v.push_back ( tmp ) ;
		p.push_back ( i + 1 ) ;
	}
	long long p0 = 1 - m ;
	for ( int i = 0 ; i < n ; i++ ) {
		a.push_back ( p0 ) ;
		b.push_back ( p0 ) ;
		p0 += v [ i ] ;
	}
	std::sort ( b.begin ( ) , b.end ( ) ) ;
	for ( int i = 0 ; i < n ; i++ )
		if ( b [ i ] != p [ i ] ) {
			printf ( "-1\n" ) ;
			return 0 ;
		}
	for ( int i = 0 ; i < n ; i++ )
		printf ( "%d" , a [ i ] ) ;
	printf ( "\n" ) ;
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> vec(n-1);
	for(int i = 0; i < n-1; i++){
		cin >> vec[i];
	}
	int start = 1;
	for(int i = 0; i < n-1; i++){
		if(start + vec[0] > 0 && start + vec[0] <= n){
			break;
		}
		start++;
	}
	if(start > n || start < 0){
		cout << -1 << endl;
		return 0;
	}
	vector<int> result;
	result.push_back(start);
	bool find = false;
	vector<bool> visited(n+10000);
	visited[start] = true;
	for(int i = 0; i < vec.size() && find != true; i++){
		int x = start + vec[i];
		if(x < 0 || x > n || visited[x] == true) find = true;
		result.push_back(x);
		start = x;
		visited[start] = true;
	}
	if(find == true){
		cout << "-1" << endl;
		return 0;
	}
	for(int a : result){
		cout << a << " ";
	}
}


#include<bits/stdc++.h>
#define in cin
using namespace std;
int main(){
//	ifstream in("test.txt");
	int n;
	in >> n;
	vector<int> vec(n-1);
	for(int i = 0; i < n-1; i++){
		in >> vec[i];
	}
	int start = 1;
	for(int i = 0; i < n-1; i++){
		if(start + vec[0] > 0 && start + vec[0] <= n){
			break;
		}
		start++;
	}
	if(start > n || start < 0){
		cout << -1 << endl;
		return 0;
	}
	vector<int> result;
	result.push_back(start);
	bool find = false;
	vector<bool> visited(n+10000);
	visited[start] = true;
	for(int i = 0; i < vec.size() && find != true; i++){
		int x = start + vec[i];
		if(x < 0 || x > n || visited[x] == true){
			find = true;
			break;
		}
		result.push_back(x);
		start = x;
		visited[start] = true;
	}
	if(find == true){
		cout << "-1" << endl;
		return 0;
	}
	for(int a : result){
		cout << a << " ";
	}
}


#include<bits/stdc++.h>
#define in cin
using namespace std;
int main(){
//	ifstream in("test.txt");
	int n;
	in >> n;
	vector<int> vec(n-1);
	for(int i = 0; i < n-1; i++){
		in >> vec[i];
	}
	int start = 1;
	for(int i = 0; i < n-1; i++){
		if(start + vec[0] > 0 && start + vec[0] <= n){
			break;
		}
		start++;
	}
	if(start > n || start < 0){
		cout << -1 << endl;
		return 0;
	}
	vector<int> result;
	bool find = false;
	for(int a = start; a <= n; a++){
		start = a;
		result.clear();
		result.push_back(start);
		find = false;
		vector<bool> visited(n+10000);
		visited[start] = true;
		for(int i = 0; i < vec.size() && find != true; i++){
			int x = start + vec[i];
			if(x < 0 || x > n || visited[x] == true){
				find = true;
				break;
			}
			result.push_back(x);
			start = x;
			visited[start] = true;
		}
		if(find == false){
			for(int a : result){
				cout << a << " ";
			}
			return 0;
		}
	}
	cout << -1 << endl;
}


#include <bits/stdc++.h>

#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>

using namespace std;
const int N = 200005;
ll t, n, m, k, a, b, x, y, ans, arr[N];
string s;
ll mod = 998244353;
bool vis[N];
int dp[503][503];
vector<ll> err;

int main() {
    io;
    t = 1;
//    cin >> t;
    while (t--) {
        // I was born to be a fuckin' stupid piece of shit.
        cin >> n >> m >> b >> mod;
        err.resize(n, 0);
        dp[0][0] = 1 % mod;
        for (int i = 0; i < n; ++i) cin >> err[i];
        sort(err.begin(), err.end());
        for (int i = 0; i < n; ++i) {
            for (int j = 1; j <= m; ++j) {
                for (int k = err[i]; k <= b; ++k) {
                    dp[j][k] += dp[j - 1][k - err[i]];
                    if (dp[j][k] >= mod)
                        dp[j][k] -= mod;
                }
            }
        }
        for (int i = 0; i <= b; ++i) {
            ans += dp[m][i];
            if (ans >= mod)
                ans -= mod;
        }
        cout << ans << endl;
    }
    return 0;
}
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);


#include <bits/stdc++.h>
using namespace std;
int t[507], dp[507][507];
int main() {
  long long n, m, b, mod, w = 0;
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 0;i <= m;i++)
      for(int j = b;j >= 0;j--)
        dp[i][j] = dp[i][j] + dp[i - 1][j - t[n]];
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
unsigned long long t[507], dp[507][507], n, m, b, mod, w = 0;
int main() {
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 1;i <= m;i++)
      for(int j = b;j >= 0;j--)
        if(j >= t[n])
          dp[i][j] = (dp[i][j] + dp[i - 1][j - t[n]]) % mod;
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
int t[507], dp[507][507];
int main() {
  long long n, m, b, mod, w = 0;
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 0;i <= m;i++)
      for(int j = b;j >= 0;j--)
        dp[i][j] = (dp[i][j] + dp[i - 1][j - t[n]]) % mod;
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
unsigned long long t[507], dp[507][507], n, m, b, mod, w = 0;
int main() {
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 1;i <= m;i++)
      for(int j = b;j >= 0;j--)
        if(j >= t[n])
          dp[i][j] = (dp[i][j] + dp[i - 1][j - t[n]]);
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
long long t[507], dp[507][507];
int main() {
  long long n, m, b, mod, w = 0;
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 1;i <= m;i++)
      for(int j = b;j >= 0;j--)
        dp[i][j] = (dp[i][j] + dp[i - 1][j - t[n]]) % mod;
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
int t[507], dp[507][507];
int main() {
  int n, m, b, mod, w = 0;
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 0;i <= m;i++)
      for(int j = b;j >= 0;j--)
        dp[i][j] = (dp[i][j] + dp[i - 1][j - t[n]]) % mod;
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
int t[507], dp[507][507];
int main() {
  long long n, m, b, mod, w = 0;
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 1;i <= m;i++)
      for(int j = b;j >= 0;j--)
        dp[i][j] = dp[i][j] + dp[i - 1][j - t[n]];
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
int t[507], dp[507][507];
int main() {
  long long n, m, b, mod, w = 0;
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 1;i <= m;i++)
      for(int j = b;j >= 0;j--)
        dp[i][j] = (dp[i][j] + dp[i - 1][j - t[n]]) % mod;
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
unsigned long long t[507], dp[507][507], n, m, b, mod, w = 0;
int main() {
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 1;i <= m;i++)
      for(int j = b;j >= 0;j--)
        dp[i][j] = (dp[i][j] + dp[i - 1][j - t[n]]);
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include <bits/stdc++.h>
using namespace std;
unsigned long long t[507], dp[507][507], n, m, b, mod, w = 0;
int main() {
  cin >> n >> m >> b >> mod;
  for(int i = 0;i < n;i++)
    cin >> t[i];
  dp[0][0] = 1;
  while(n--)
    for(int i = 1;i <= m;i++)
      for(int j = b;j >= t[n];j--)
        dp[i][j] = (dp[i][j] + dp[i - 1][j - t[n]]) % mod;
  for(int i = 0;i <= b;i++)
    w = (w + dp[m][i]) % mod;
  cout << w;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
// #define mod 1000000007
const int N=505;
ll n,m,b,mod;
ll arr[N];
ll solve(ll i , ll bugs , ll line_rem)
{
    // cout<<i<<" "<<bugs<<" "<<line_rem<<"\n";
    if( i == n-1 )
    {
        bugs += line_rem*arr[i];
        if( bugs <= b)
            return 1;
    }
    if(bugs > b )return 0;
    ll ways = 0;
    for(int j=0;j<=line_rem ; j++)
    {
        ways = (ways + solve(i+1 , bugs+(j)*arr[i]  , line_rem - (j) ))%mod;
    }
    return ways;
}
int main()
{
    fast;
    cin>>n>>m>>b>>mod;
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<solve(0,0,m);
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
// #define mod 1000000007
const int N=505;
ll n,m,b,mod;
ll arr[N];
ll dp[N][N];
ll solve(ll i , ll bugs , ll line_rem)
{
    // cout<<i<<" "<<bugs<<" "<<line_rem<<"\n";
    if( i == n-1 )
    {
        bugs += line_rem*arr[i];
        if( bugs <= b)
            return 1;
    }
    if(bugs > b )return 0;
    ll ways = 0;
    if(dp[bugs][line_rem]!=-1)return dp[bugs][line_rem];
    for(int j=0;j<=line_rem ; j++)
    {
        ways = (ways + solve(i+1 , bugs+(j)*arr[i]  , line_rem - (j) ))%mod;
    }
    return dp[bugs][line_rem]=ways;
}
int main()
{
    fast;
    cin>>n>>m>>b>>mod;
    memset(dp , -1 , sizeof dp);
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<solve(0,0,m);
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
// #define mod 1000000007
const int N=505;
ll n,m,b,mod;
ll a[N];
ll dp[N][N];
// ll solve(ll i , ll bugs , ll line_rem)
// {
//     // cout<<i<<" "<<bugs<<" "<<line_rem<<"\n";
//     if( i == n-1 )
//     {
//         bugs += line_rem*arr[i];
//         if( bugs <= b)
//             return 1;
//     }
//     if(bugs > b )return 0;
//     ll ways = 0;
//     // if(dp[i][bugs][line_rem]!=-1)return dp[i][bugs][line_rem];
//     for(int j=0;j<=line_rem ; j++)
//     {
//         ways = (ways + solve(i+1 , bugs+(j)*arr[i]  , line_rem - (j) ))%mod;
//     }
//     return ways;
// }
int main()
{
    fast;
    cin>>n>>m>>b>>mod;
    memset(dp , 0 , sizeof dp);
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0][0]=1;
    for(int i=0;i<n;i++) {
        for(int j=0;j<=m;j++) {
            for(int bug = 0 ; bug+a[i]<=b ; bug++ ) {
                dp[j+1][bug+a[i]] = (dp[j+1][bug+a[i]] + dp[j][bug])%mod ;
            }
        }
    }
    ll ans = 0;
    for(int i=0; i <= b ; i++)ans = (ans+dp[m][i])%mod;
    cout<<ans<<"\n";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
// #define mod 1000000007
const int N=505;
ll n,m,b,mod;
ll arr[N];
ll dp[N][N];
ll solve(ll i , ll bugs , ll line_rem)
{
    // cout<<i<<" "<<bugs<<" "<<line_rem<<"\n";
    if( i == n-1 )
    {
        bugs += line_rem*arr[i];
        if( bugs <= b)
            return 1;
    }
    if(bugs > b )return 0;
    ll ways = 0;
    if(dp[i][line_rem]!=-1)return dp[i][line_rem];
    for(int j=0;j<=line_rem ; j++)
    {
        ways = (ways + solve(i+1 , bugs+(j)*arr[i]  , line_rem - (j) ))%mod;
    }
    return dp[i][line_rem]=ways;
}
int main()
{
    fast;
    cin>>n>>m>>b>>mod;
    memset(dp , -1 , sizeof dp);
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<solve(0,0,m);
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
// #define mod 1000000007
const int N=505;
ll n,m,b,mod;
ll arr[N];
ll dp[N][N][N];
ll solve(ll i , ll bugs , ll line_rem)
{
    // cout<<i<<" "<<bugs<<" "<<line_rem<<"\n";
    if( i == n-1 )
    {
        bugs += line_rem*arr[i];
        if( bugs <= b)
            return 1;
    }
    if(bugs > b )return 0;
    ll ways = 0;
    if(dp[i][bugs][line_rem]!=-1)return dp[i][bugs][line_rem];
    for(int j=0;j<=line_rem ; j++)
    {
        ways = (ways + solve(i+1 , bugs+(j)*arr[i]  , line_rem - (j) ))%mod;
    }
    return dp[i][bugs][line_rem]=ways;
}
int main()
{
    fast;
    cin>>n>>m>>b>>mod;
    memset(dp , -1 , sizeof dp);
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<solve(0,0,m);
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
// #define mod 1000000007
const int N=505;
ll n,m,b,mod;
ll arr[N];
ll dp[101][N][N];
ll solve(ll i , ll bugs , ll line_rem)
{
    // cout<<i<<" "<<bugs<<" "<<line_rem<<"\n";
    if( i == n-1 )
    {
        bugs += line_rem*arr[i];
        if( bugs <= b)
            return 1;
    }
    if(bugs > b )return 0;
    ll ways = 0;
    if(dp[i][bugs][line_rem]!=-1)return dp[i][bugs][line_rem];
    for(int j=0;j<=line_rem ; j++)
    {
        ways = (ways + solve(i+1 , bugs+(j)*arr[i]  , line_rem - (j) ))%mod;
    }
    return dp[i][bugs][line_rem]=ways;
}
int main()
{
    fast;
    cin>>n>>m>>b>>mod;
    memset(dp , -1 , sizeof dp);
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<solve(0,0,m);
return 0;
}


#include <iostream>
#define nmax 500
#define mmax 500
#define bmax 500
using std::cin;
using std::cout;
int n, m, b, mod;
int a[nmax+1], dp[2][nmax+1][bmax+1];
void in()
{
    cin >> n >> m >> b >> mod;
    for(int i = 1; i <= n; ++i)
      cin >> a[i];
}
///chia du nhanh voi cac so nho hon 2 lan mod
int qmod(int x)
{
    return (x < mod) ? x : x - mod;
}
void prs()
{
    ///de tao 0 dong code mat 0 loi du xet bao nhieu nguoi thi van co 1 cach
    for(int i = 0; i <= n; ++i)
      dp[0][i][0] = qmod(1);
    for(int j = 1; j <= m; ++j){
      int o = j & 1;
      for(int i = 1; i <= n; ++i)
        for(int k = 0; k <= b; ++k){
          dp[o][i][k] = dp[!o][i - 1][k];
          if(a[i] <= k) dp[o][i][k] = qmod(dp[o][i][k] + dp[!o][i][k - a[i]]);
        }
    }
}
void out()
{
    int ans = 0;
    for(int i = 0; i <= b; ++i)
      ans = qmod(ans + dp[m & 1][n][i]);
    cout << ans;
}
void run()
{
    in();
    prs();
    out();
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}


#include <iostream>
#define nmax 500
#define mmax 500
#define bmax 500
using std::cin;
using std::cout;
int n, m, b, mod;
int a[nmax+1], dp[2][nmax+1][bmax+1];
void in()
{
    cin >> n >> m >> b >> mod;
    for(int i = 1; i <= n; ++i)
      cin >> a[i];
}
///chia du nhanh voi cac so nho hon 2 lan mod
int qmod(int x)
{
    return (x < mod) ? x : x - mod;
}
void prs()
{
    ///de tao 0 dong code mat 0 loi du xet bao nhieu nguoi thi van co 1 cach
    for(int i = 0; i <= n; ++i)
      dp[0][i][0] = qmod(1);
    for(int j = 1; j <= m; ++j){
      int o = j & 1;
      for(int k = 0; k <= b; ++k)
        dp[o][0][k] = 0;
      for(int i = 1; i <= n; ++i)
        for(int k = 0; k <= b; ++k){
          dp[o][i][k] = dp[o][i - 1][k];
          if(a[i] <= k) dp[o][i][k] = qmod(dp[o][i][k] + dp[!o][i][k - a[i]]);
        }
    }
}
void out()
{
    int ans = 0;
    for(int i = 0; i <= b; ++i)
      ans = qmod(ans + dp[m & 1][n][i]);
    cout << ans;
}
void run()
{
    in();
    prs();
    out();
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}


#include <iostream>
#define nmax 500
#define mmax 500
#define bmax 500
using std::cin;
using std::cout;
int n, m, b, mod;
int a[nmax+1], dp[nmax+1][mmax+1][bmax+1];
void in()
{
    cin >> n >> m >> b >> mod;
    for(int i = 1; i <= n; ++i)
      cin >> a[i];
}
int qmod(int x)
{
    return (x < mod) ? x : x - mod;
}
void prs()
{
    for(int i = 1; i <= n; ++i)
      dp[i][0][0] = qmod(1);
    for(int j = 1; j <= m; ++j)
      for(int i = 1; i <= n; ++i)
      for(int k = 0; k <= b; ++k){
        dp[i][j][k] = dp[i - 1][j][k];
        if(a[i] <= k) dp[i][j][k] = qmod(dp[i][j][k] + dp[i][j - 1][k - a[i]]);
      }
}
void out()
{
    int ans = 0;
    for(int i = 0; i <= b; ++i)
      ans = qmod(ans + dp[n][m][i]);
    cout << ans;
}
void run()
{
    in();
    prs();
    out();
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}


#include <iostream>
#define nmax 500
#define mmax 500
#define bmax 500
using std::cin;
using std::cout;
int n, m, b, mod;
int a[nmax+1], dp[2][nmax+1][bmax+1];
void in()
{
    cin >> n >> m >> b >> mod;
    for(int i = 1; i <= n; ++i)
      cin >> a[i];
}
int qmod(int x)
{
    return (x < mod) ? x : x - mod;
}
void prs()
{
    for(int i = 0; i < 2; ++i)
      dp[0][i][0] = qmod(1);
    for(int j = 1; j <= m; ++j){
      for(int i = 1; i <= n; ++i)
        for(int k = 0; k <= b; ++k){
          dp[1][i][k] = dp[0][i][k];
          if(a[i] <= k) dp[1][i][k] = qmod(dp[1][i][k] + dp[0][i][k - a[i]]);
        }
      for(int i = 1; i <= n; ++i)
      for(int k = 0; k <= b; ++k)
        dp[0][i][k] = dp[1][i][k];
    }
}
void out()
{
    int ans = 0;
    for(int i = 0; i <= b; ++i)
      ans = qmod(ans + dp[0][n][i]);
    cout << ans;
}
void run()
{
    in();
    prs();
    out();
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}


#include <iostream>
#define nmax 500
#define mmax 500
#define bmax 500
using std::cin;
using std::cout;
int n, m, b, mod;
int a[nmax+1], dp[2][nmax+1][bmax+1];
void in()
{
    cin >> n >> m >> b >> mod;
    for(int i = 1; i <= n; ++i)
      cin >> a[i];
}
int qmod(int x)
{
    return (x < mod) ? x : x - mod;
}
void prs()
{
    for(int i = 0; i <= n; ++i)
      dp[0][i][0] = qmod(1);
    for(int j = 1; j <= m; ++j){
      for(int i = 1; i <= n; ++i)
        for(int k = 0; k <= b; ++k){
          dp[1][i][k] = dp[1][i - 1][k];
          if(a[i] <= k) dp[1][i][k] = qmod(dp[1][i][k] + dp[0][i][k - a[i]]);
        }
      for(int i = 1; i <= n; ++i)
      for(int k = 0; k <= b; ++k)
        dp[0][i][k] = dp[1][i][k];
    }
}
void out()
{
    int ans = 0;
    for(int i = 0; i <= b; ++i)
      ans = qmod(ans + dp[0][n][i]);
    cout << ans;
}
void run()
{
    in();
    prs();
    out();
}
int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
//	public static int[][][] dp;
	public static void main(String[] args) throws NumberFormatException,
	IOException {
		ContestScanner in = new ContestScanner();
		int n = in.nextInt();
		int m = in.nextInt();
		int b = in.nextInt();
		int mod = in.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = in.nextInt();
		}
//		dp = new int[m+1][b+1][n+1];
		long[][] dp1 = new long[b+1][n+1];
//		int[][][] dp2 = new int[m+1][501][n+1];
//		for(int i=0; i<n; i++){
//			dp[1][a[i]][i]++;
//			if(dp[1][a[i]][i] >= mod) dp[1][a[i]][i] %= mod;
//		}
//		for(int i=0; i<=b; i++){
//			int imos = 0;
//			for(int j=0; j<n; j++){
//				int add = imos;
//				imos += dp[1][i][j];
//				dp[1][i][j] += add;
//			}
//		}
		for(int i=0; i<n; i++){
			dp1[a[i]][i]++;
			if(dp1[a[i]][i] >= mod) dp1[a[i]][i] %= mod;
		}
		for(int i=0; i<=b; i++){
			long imos = 0;
			for(int j=0; j<n; j++){
				long add = imos;
				imos += dp1[i][j];
				dp1[i][j] += add;
			}
		}
//		int[][] imos = new int[][n];
		long[][] olddp = new long[b+1][n];
		for(int i=0; i<=b; i++){
			for(int j=0; j<n; j++){
				olddp[i][j] = dp1[i][j];
			}
		}
		for(int i=2; i<=m; i++){
			dp1 = new long[b+1][n];
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					if(a[k]+j > b) continue;
					dp1[j+a[k]][k] += olddp[j][k];
					if(dp1[j+a[k]][k] >= mod) dp1[j+a[k]][k] %= mod;
//					for(int l=0; l<=k; l++){
//						dp[i][j+a[k]][k] += dp[i-1][j][l];
//						if(dp[i][j+a[k]][l] >= mod) dp[i][j+a[k]][l] %= mod;
//					}
				}
			}
			for(int j=0; j<=b; j++){
				long imos = 0;
				for(int k=0; k<n; k++){
					long add = imos;
					imos += dp1[j][k];
					dp1[j][k] += add;
					if(dp1[j][k] >= mod) dp1[j][k] %= mod;
				}
			}
			olddp = new long[b+1][n];
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					olddp[j][k] = dp1[j][k];
				}
			}
		}
		long sum = 0;
		for(int i=0; i<=b; i++){
			sum += dp1[i][n-1];
			if(sum >= mod) sum %= mod;
		}
		System.out.println(sum);
	}

}

class Node{
	int id;
	HashSet<Node> edge = new HashSet<Node>();
	public Node(int id) {
		this.id = id;
	}
	public void createEdge(Node node) {
		edge.add(node);
	}
}

class MyComp implements Comparator<int[]> {
	final int idx;
	public MyComp(int idx){
		this.idx = idx;
	}
	public int compare(int[] a, int[] b) {
		return a[idx] - b[idx];
	}
}

class Reverse implements Comparator<Integer> {
	public int compare(Integer arg0, Integer arg1) {
		return arg1 - arg0;
	}
}

class ContestWriter {
	private PrintWriter out;

	public ContestWriter(String filename) throws IOException {
		out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
	}

	public ContestWriter() throws IOException {
		out = new PrintWriter(System.out);
	}

	public void println(String str) {
		out.println(str);
	}

	public void print(String str) {
		out.print(str);
	}

	public void close() {
		out.close();
	}
}

class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;

	public ContestScanner() throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(
				filename)));
	}

	public String nextToken() throws IOException {
		if (line == null || line.length <= idx) {
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}

	public String readLine() throws IOException{
		return reader.readLine();
	}

	public long nextLong() throws IOException, NumberFormatException {
		return Long.parseLong(nextToken());
	}

	public int nextInt() throws NumberFormatException, IOException {
		return (int) nextLong();
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
	public static int[][][] dp;
	public static void main(String[] args) throws NumberFormatException,
	IOException {
		ContestScanner in = new ContestScanner();
		int n = in.nextInt();
		int m = in.nextInt();
		int b = in.nextInt();
		int mod = in.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = in.nextInt();
		}
		dp = new int[m+1][b+1][n+1];
//		int[][][] dp2 = new int[m+1][501][n+1];
		for(int i=0; i<n; i++){
			dp[1][a[i]][i]++;
			if(dp[1][a[i]][i] >= mod) dp[1][a[i]][i] %= mod;
		}
		for(int i=0; i<=b; i++){
			int imos = 0;
			for(int j=0; j<n; j++){
				int add = imos;
				imos += dp[1][i][j];
				dp[1][i][j] += add;
			}
		}
//		int[][] imos = new int[][n];
		for(int i=2; i<=m; i++){
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					if(a[k]+j > b) continue;
					dp[i][j+a[k]][k] += dp[i-1][j][k];
					if(dp[i][j+a[k]][k] >= mod) dp[i][j+a[k]][k] %= mod;
//					for(int l=0; l<=k; l++){
//						dp[i][j+a[k]][k] += dp[i-1][j][l];
//						if(dp[i][j+a[k]][l] >= mod) dp[i][j+a[k]][l] %= mod;
//					}
				}
			}
			for(int j=0; j<=b; j++){
				int imos = 0;
				for(int k=0; k<n; k++){
					int add = imos;
					imos += dp[i][j][k];
					dp[i][j][k] += add;
					if(dp[i][j][k] >= mod) dp[i][j][k] %= mod;
				}
			}
		}
		int sum = 0;
		for(int i=0; i<=b; i++){
			sum += dp[m][i][n-1];
			if(sum >= mod) sum %= mod;
		}
		System.out.println(sum);
	}

}

class Node{
	int id;
	HashSet<Node> edge = new HashSet<Node>();
	public Node(int id) {
		this.id = id;
	}
	public void createEdge(Node node) {
		edge.add(node);
	}
}

class MyComp implements Comparator<int[]> {
	final int idx;
	public MyComp(int idx){
		this.idx = idx;
	}
	public int compare(int[] a, int[] b) {
		return a[idx] - b[idx];
	}
}

class Reverse implements Comparator<Integer> {
	public int compare(Integer arg0, Integer arg1) {
		return arg1 - arg0;
	}
}

class ContestWriter {
	private PrintWriter out;

	public ContestWriter(String filename) throws IOException {
		out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
	}

	public ContestWriter() throws IOException {
		out = new PrintWriter(System.out);
	}

	public void println(String str) {
		out.println(str);
	}

	public void print(String str) {
		out.print(str);
	}

	public void close() {
		out.close();
	}
}

class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;

	public ContestScanner() throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(
				filename)));
	}

	public String nextToken() throws IOException {
		if (line == null || line.length <= idx) {
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}

	public String readLine() throws IOException{
		return reader.readLine();
	}

	public long nextLong() throws IOException, NumberFormatException {
		return Long.parseLong(nextToken());
	}

	public int nextInt() throws NumberFormatException, IOException {
		return (int) nextLong();
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
	public static int[][][] dp;
	public static void main(String[] args) throws NumberFormatException,
	IOException {
		ContestScanner in = new ContestScanner();
		int n = in.nextInt();
		int m = in.nextInt();
		int b = in.nextInt();
		int mod = in.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = in.nextInt();
		}
//		dp = new int[m+1][b+1][n+1];
		long[][] dp1 = new long[b+1][n+1];
//		int[][][] dp2 = new int[m+1][501][n+1];
//		for(int i=0; i<n; i++){
//			dp[1][a[i]][i]++;
//			if(dp[1][a[i]][i] >= mod) dp[1][a[i]][i] %= mod;
//		}
//		for(int i=0; i<=b; i++){
//			int imos = 0;
//			for(int j=0; j<n; j++){
//				int add = imos;
//				imos += dp[1][i][j];
//				dp[1][i][j] += add;
//			}
//		}
		for(int i=0; i<n; i++){
			dp1[a[i]][i]++;
			if(dp1[a[i]][i] >= mod) dp1[a[i]][i] %= mod;
		}
		for(int i=0; i<=b; i++){
			int imos = 0;
			for(int j=0; j<n; j++){
				int add = imos;
				imos += dp1[i][j];
				dp1[i][j] += add;
			}
		}
//		int[][] imos = new int[][n];
		long[][] olddp = new long[b+1][n+1];
		for(int i=0; i<=b; i++){
			for(int j=0; j<n; j++){
				olddp[i][j] = dp1[i][j];
			}
		}
		for(int i=2; i<=m; i++){
			dp1 = new long[b+1][n+1];
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					if(a[k]+j > b) continue;
					dp1[j+a[k]][k] += olddp[j][k];
					if(dp1[j+a[k]][k] >= mod) dp1[j+a[k]][k] %= mod;
//					for(int l=0; l<=k; l++){
//						dp[i][j+a[k]][k] += dp[i-1][j][l];
//						if(dp[i][j+a[k]][l] >= mod) dp[i][j+a[k]][l] %= mod;
//					}
				}
			}
			for(int j=0; j<=b; j++){
				int imos = 0;
				for(int k=0; k<n; k++){
					int add = imos;
					imos += dp1[j][k];
					dp1[j][k] += add;
					if(dp1[j][k] >= mod) dp1[j][k] %= mod;
				}
			}
			olddp = new long[b+1][n+1];
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					olddp[j][k] = dp1[j][k];
				}
			}
		}
		int sum = 0;
		for(int i=0; i<=b; i++){
			sum += dp1[i][n-1];
			if(sum >= mod) sum %= mod;
		}
		System.out.println(sum);
	}

}

class Node{
	int id;
	HashSet<Node> edge = new HashSet<Node>();
	public Node(int id) {
		this.id = id;
	}
	public void createEdge(Node node) {
		edge.add(node);
	}
}

class MyComp implements Comparator<int[]> {
	final int idx;
	public MyComp(int idx){
		this.idx = idx;
	}
	public int compare(int[] a, int[] b) {
		return a[idx] - b[idx];
	}
}

class Reverse implements Comparator<Integer> {
	public int compare(Integer arg0, Integer arg1) {
		return arg1 - arg0;
	}
}

class ContestWriter {
	private PrintWriter out;

	public ContestWriter(String filename) throws IOException {
		out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
	}

	public ContestWriter() throws IOException {
		out = new PrintWriter(System.out);
	}

	public void println(String str) {
		out.println(str);
	}

	public void print(String str) {
		out.print(str);
	}

	public void close() {
		out.close();
	}
}

class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;

	public ContestScanner() throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(
				filename)));
	}

	public String nextToken() throws IOException {
		if (line == null || line.length <= idx) {
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}

	public String readLine() throws IOException{
		return reader.readLine();
	}

	public long nextLong() throws IOException, NumberFormatException {
		return Long.parseLong(nextToken());
	}

	public int nextInt() throws NumberFormatException, IOException {
		return (int) nextLong();
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
	public static int[][][] dp;
	public static void main(String[] args) throws NumberFormatException,
	IOException {
		ContestScanner in = new ContestScanner();
		int n = in.nextInt();
		int m = in.nextInt();
		int b = in.nextInt();
		int mod = in.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = in.nextInt();
		}
//		dp = new int[m+1][b+1][n+1];
		int[][] dp1 = new int[b+1][n+1];
//		int[][][] dp2 = new int[m+1][501][n+1];
//		for(int i=0; i<n; i++){
//			dp[1][a[i]][i]++;
//			if(dp[1][a[i]][i] >= mod) dp[1][a[i]][i] %= mod;
//		}
//		for(int i=0; i<=b; i++){
//			int imos = 0;
//			for(int j=0; j<n; j++){
//				int add = imos;
//				imos += dp[1][i][j];
//				dp[1][i][j] += add;
//			}
//		}
		for(int i=0; i<n; i++){
			dp1[a[i]][i]++;
			if(dp1[a[i]][i] >= mod) dp1[a[i]][i] %= mod;
		}
		for(int i=0; i<=b; i++){
			int imos = 0;
			for(int j=0; j<n; j++){
				int add = imos;
				imos += dp1[i][j];
				dp1[i][j] += add;
			}
		}
//		int[][] imos = new int[][n];
		int[][] olddp = new int[b+1][n+1];
		for(int i=0; i<=b; i++){
			for(int j=0; j<n; j++){
				olddp[i][j] = dp1[i][j];
			}
		}
		for(int i=2; i<=m; i++){
			dp1 = new int[b+1][n+1];
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					if(a[k]+j > b) continue;
					dp1[j+a[k]][k] += olddp[j][k];
					if(dp1[j+a[k]][k] >= mod) dp1[j+a[k]][k] %= mod;
//					for(int l=0; l<=k; l++){
//						dp[i][j+a[k]][k] += dp[i-1][j][l];
//						if(dp[i][j+a[k]][l] >= mod) dp[i][j+a[k]][l] %= mod;
//					}
				}
			}
			for(int j=0; j<=b; j++){
				int imos = 0;
				for(int k=0; k<n; k++){
					int add = imos;
					imos += dp1[j][k];
					dp1[j][k] += add;
					if(dp1[j][k] >= mod) dp1[j][k] %= mod;
				}
			}
			olddp = new int[b+1][n+1];
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					olddp[j][k] = dp1[j][k];
				}
			}
		}
		int sum = 0;
		for(int i=0; i<=b; i++){
			sum += dp1[i][n-1];
			if(sum >= mod) sum %= mod;
		}
		System.out.println(sum);
	}

}

class Node{
	int id;
	HashSet<Node> edge = new HashSet<Node>();
	public Node(int id) {
		this.id = id;
	}
	public void createEdge(Node node) {
		edge.add(node);
	}
}

class MyComp implements Comparator<int[]> {
	final int idx;
	public MyComp(int idx){
		this.idx = idx;
	}
	public int compare(int[] a, int[] b) {
		return a[idx] - b[idx];
	}
}

class Reverse implements Comparator<Integer> {
	public int compare(Integer arg0, Integer arg1) {
		return arg1 - arg0;
	}
}

class ContestWriter {
	private PrintWriter out;

	public ContestWriter(String filename) throws IOException {
		out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
	}

	public ContestWriter() throws IOException {
		out = new PrintWriter(System.out);
	}

	public void println(String str) {
		out.println(str);
	}

	public void print(String str) {
		out.print(str);
	}

	public void close() {
		out.close();
	}
}

class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;

	public ContestScanner() throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(
				filename)));
	}

	public String nextToken() throws IOException {
		if (line == null || line.length <= idx) {
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}

	public String readLine() throws IOException{
		return reader.readLine();
	}

	public long nextLong() throws IOException, NumberFormatException {
		return Long.parseLong(nextToken());
	}

	public int nextInt() throws NumberFormatException, IOException {
		return (int) nextLong();
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
//	public static int[][][] dp;
	public static void main(String[] args) throws NumberFormatException,
	IOException {
		ContestScanner in = new ContestScanner();
		int n = in.nextInt();
		int m = in.nextInt();
		int b = in.nextInt();
		int mod = in.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = in.nextInt();
		}
		int[][] dp = new int[m+1][b+1];
		dp[0][0] = 1;
		for(int i=0; i<n; i++){
			for(int j=1; j<=m; j++){
				for(int k=0; k+a[i]<=b; k++){
					dp[j][k+a[i]] += dp[j-1][k];
					if(dp[j][k+a[i]] >= mod) dp[j][k+a[i]] %= mod;
				}
			}
		}
		int sum = 0;
		for(int i=0; i<=b; i++){
			sum += dp[m][i];
			if(sum >= mod) sum %= mod;
		}
		System.out.println(sum);
	}

}

class Node{
	int id;
	HashSet<Node> edge = new HashSet<Node>();
	public Node(int id) {
		this.id = id;
	}
	public void createEdge(Node node) {
		edge.add(node);
	}
}

class MyComp implements Comparator<int[]> {
	final int idx;
	public MyComp(int idx){
		this.idx = idx;
	}
	public int compare(int[] a, int[] b) {
		return a[idx] - b[idx];
	}
}

class Reverse implements Comparator<Integer> {
	public int compare(Integer arg0, Integer arg1) {
		return arg1 - arg0;
	}
}

class ContestWriter {
	private PrintWriter out;

	public ContestWriter(String filename) throws IOException {
		out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
	}

	public ContestWriter() throws IOException {
		out = new PrintWriter(System.out);
	}

	public void println(String str) {
		out.println(str);
	}

	public void print(String str) {
		out.print(str);
	}

	public void close() {
		out.close();
	}
}

class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;

	public ContestScanner() throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(
				filename)));
	}

	public String nextToken() throws IOException {
		if (line == null || line.length <= idx) {
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}

	public String readLine() throws IOException{
		return reader.readLine();
	}

	public long nextLong() throws IOException, NumberFormatException {
		return Long.parseLong(nextToken());
	}

	public int nextInt() throws NumberFormatException, IOException {
		return (int) nextLong();
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class Main {
//	public static int[][][] dp;
	public static void main(String[] args) throws NumberFormatException,
	IOException {
		ContestScanner in = new ContestScanner();
		int n = in.nextInt();
		int m = in.nextInt();
		int b = in.nextInt();
		int mod = in.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = in.nextInt();
		}
//		dp = new int[m+1][b+1][n+1];
		long[][] dp1 = new long[b+1][n+1];
//		int[][][] dp2 = new int[m+1][501][n+1];
//		for(int i=0; i<n; i++){
//			dp[1][a[i]][i]++;
//			if(dp[1][a[i]][i] >= mod) dp[1][a[i]][i] %= mod;
//		}
//		for(int i=0; i<=b; i++){
//			int imos = 0;
//			for(int j=0; j<n; j++){
//				int add = imos;
//				imos += dp[1][i][j];
//				dp[1][i][j] += add;
//			}
//		}
		for(int i=0; i<n; i++){
			dp1[a[i]][i]++;
			if(dp1[a[i]][i] >= mod) dp1[a[i]][i] %= mod;
		}
		for(int i=0; i<=b; i++){
			int imos = 0;
			for(int j=0; j<n; j++){
				int add = imos;
				imos += dp1[i][j];
				dp1[i][j] += add;
				if(imos >= mod) imos %= mod;
				if(dp1[i][j] >= mod) dp1[i][j] %= mod;
			}
		}
//		int[][] imos = new int[][n];
		long[][] olddp = new long[b+1][n];
		for(int i=0; i<=b; i++){
			for(int j=0; j<n; j++){
				olddp[i][j] = dp1[i][j];
			}
		}
		for(int i=2; i<=m; i++){
			dp1 = new long[b+1][n];
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					if(a[k]+j > b) continue;
					dp1[j+a[k]][k] += olddp[j][k];
					if(dp1[j+a[k]][k] >= mod) dp1[j+a[k]][k] %= mod;
//					for(int l=0; l<=k; l++){
//						dp[i][j+a[k]][k] += dp[i-1][j][l];
//						if(dp[i][j+a[k]][l] >= mod) dp[i][j+a[k]][l] %= mod;
//					}
				}
			}
			for(int j=0; j<=b; j++){
				int imos = 0;
				for(int k=0; k<n; k++){
					int add = imos;
					imos += dp1[j][k];
					dp1[j][k] += add;
					if(dp1[j][k] >= mod) dp1[j][k] %= mod;
					if(imos >= mod) imos %= mod;
				}
			}
			olddp = new long[b+1][n];
			for(int j=0; j<=b; j++){
				for(int k=0; k<n; k++){
					olddp[j][k] = dp1[j][k];
				}
			}
		}
		int sum = 0;
		for(int i=0; i<=b; i++){
			sum += dp1[i][n-1];
			if(sum >= mod) sum %= mod;
		}
		System.out.println(sum);
	}

}

class Node{
	int id;
	HashSet<Node> edge = new HashSet<Node>();
	public Node(int id) {
		this.id = id;
	}
	public void createEdge(Node node) {
		edge.add(node);
	}
}

class MyComp implements Comparator<int[]> {
	final int idx;
	public MyComp(int idx){
		this.idx = idx;
	}
	public int compare(int[] a, int[] b) {
		return a[idx] - b[idx];
	}
}

class Reverse implements Comparator<Integer> {
	public int compare(Integer arg0, Integer arg1) {
		return arg1 - arg0;
	}
}

class ContestWriter {
	private PrintWriter out;

	public ContestWriter(String filename) throws IOException {
		out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
	}

	public ContestWriter() throws IOException {
		out = new PrintWriter(System.out);
	}

	public void println(String str) {
		out.println(str);
	}

	public void print(String str) {
		out.print(str);
	}

	public void close() {
		out.close();
	}
}

class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;

	public ContestScanner() throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(
				filename)));
	}

	public String nextToken() throws IOException {
		if (line == null || line.length <= idx) {
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}

	public String readLine() throws IOException{
		return reader.readLine();
	}

	public long nextLong() throws IOException, NumberFormatException {
		return Long.parseLong(nextToken());
	}

	public int nextInt() throws NumberFormatException, IOException {
		return (int) nextLong();
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.io.*;
import java.math.*;
import java.util.*;

public class Program {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;

    static final int MOD = 1000000007;
    static final double INF = 10000000000.0;
    static final int MAX = 10000001;

    void solve() throws IOException {
    	int n, m, b, mod;
    	int[] a;
    	int[][][] dp;
    	n = nextInt();
    	m = nextInt();
    	b = nextInt();
    	mod = nextInt();
    	a = new int[n];
    	for(int i = 0; i < n; i++)
    		a[i] = nextInt();
    	dp = new int[2][m+1][b+1];
    	dp[0][0][0] = 1;
    	for(int i = 1; i <= n; i++)
    		for(int j = 0; j <= m; j++)
    			for(int k = 0; k <= b; k++)
    			{
    				int ind = i & 1;
    				dp[ind][j][k] = dp[ind^1][j][k];
    				if (j > 0 && k >= a[i-1])
    					dp[ind][j][k] += dp[ind][j-1][k-a[i-1]];
    				while(dp[ind][j][k] >= mod)
    					dp[ind][j][k] -= mod;
    			}
    	int ans = 0;
    	for(int i = 0; i <= b; i++)
    	{
    		ans += dp[n&1][m][i];
    		while(ans >= mod)
    			ans -= mod;
    	}
    	out.println(ans);
    }

    Program() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Program();
    }

    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }

    String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    class Pair implements Comparable<Pair>{

        char first;
        int second;

        public Pair(char an1, int an2){
            first = an1;
            second = an2;
        }

        @Override
        public int compareTo(Pair o) {
            if (first - o.first == 0)
            	return second - o.second;
            else
            	return first - o.first;
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Code implements Runnable {
  int nextInt(StreamTokenizer in) throws Exception {
    in.nextToken();
    return (int) in.nval;
  }

  @Override
  public void run() {
    try {
      StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
      int n = nextInt(in);
      int m = nextInt(in);
      int b = nextInt(in);
      long mod = nextInt(in);
      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = nextInt(in);
      }

      long[][] cur = new long[m + 1][b + 1];
      long[][] next = new long[m + 1][b + 1];
      cur[0][0] = 1;
      for (int i = 0; i < n; i++) {
        for (int mm = 0; mm <= m; mm++) {
          for (int bb = 0; bb <= b; bb++) {
            next[mm][bb] = cur[mm][bb];
            if (mm > 0 && bb >= a[i]) {
              next[mm][bb] += next[mm - 1][bb - a[i]];
              if (next[mm][bb] >= mod) {
                next[mm][bb] -= mod;
              }
            }
          }
        }
        cur = next;
      }
      long res = 0;
      for (int bb = 0; bb <= b; bb++) {
        res += cur[m][bb];
        if (res >= mod) {
          res -= mod;
        }
      }
      System.out.println(res);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  public static void main(String[] args) {
    new Thread(new Code()).start();
  }
}


public class A {

	public A () {
		int N = sc.nextInt(), M = sc.nextInt(), B = sc.nextInt(); MOD = sc.nextInt();
		int [] A = sc.nextInts();

		long [][] F = new long [N][B+1];

		for (int n : rep(N))
			if (A[n] <= B)
				F[n][A[n]] = 1;

		for (@SuppressWarnings("unused") int m : rep(1, M)) {
			long [][] G = new long [N][B+1];
			for (int b = 0; b <= B; ++b) {
				long H = F[0][b];
				for (int j = 0; j < N; ++j) {
					int c = b + A[j];
					if (c <= B)
						G[j][c] = mod(G[j][c] + H, MOD);
					if (j < N-1)
						H = mod(H + F[j+1][b], MOD);
				}
			}
			F = G;
		}

		long res = 0;
		for (int n : rep(N))
			for (int b : req(B))
				res = mod(res + F[n][b], MOD);

		exit(res);
	}

	private static int MOD = (int) 1e9 + 7;
	private static long mod(long x, long mod) { return ((x % mod) + mod) % mod; }
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [] req(int N) { return req(0, N); }
	private static int [] req(int S, int T) { return rep(S, T+1); }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			public String nextLine() { line = null; return readLine(); }
			public String [] nextStrings() { return split(nextLine()); }
			public int [] nextInts() {
				String [] L = nextStrings();
				int [] res = new int [L.length];
				for (int i = 0; i < L.length; ++i)
					res[i] = Integer.parseInt(L[i]);
				return res;
			}
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new A(); IOUtils.exit(); }
}


public class A {

	public A () {
		int N = sc.nextInt(), M = sc.nextInt(), B = sc.nextInt(); MOD = sc.nextInt();
		int [] A = sc.nextInts();

		int [][] F = new int [N][B+1];

		for (int n : rep(N))
			if (A[n] <= B)
				F[n][A[n]] = 1;

		int [] rB = req(B), rN = rep(N);
		for (@SuppressWarnings("unused") int m : rep(1, M)) {
			int [][] G = new int [N][B+1];
			for (int b : rB) {
				int H = F[0][b];
				for (int j : rN) {
					int c = b + A[j];
					if (c <= B)
						G[j][c] = (G[j][c] + H) % MOD;
					if (j < N-1)
						H = (H + F[j+1][b]) % MOD;
				}
			}
			F = G;
		}

		long res = 0;
		for (int n : rep(N))
			for (int b : req(B))
				res = mod(res + F[n][b]);

		exit(res);
	}

	private static int MOD = (int) 1e9 + 7;
	private static long mod(long x) { return mod(x, MOD); }
	private static long mod(long x, long mod) { return ((x % mod) + mod) % mod; }
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [] req(int N) { return req(0, N); }
	private static int [] req(int S, int T) { return rep(S, T+1); }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			public String nextLine() { line = null; return readLine(); }
			public String [] nextStrings() { return split(nextLine()); }
			public int [] nextInts() {
				String [] L = nextStrings();
				int [] res = new int [L.length];
				for (int i = 0; i < L.length; ++i)
					res[i] = Integer.parseInt(L[i]);
				return res;
			}
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new A(); IOUtils.exit(); }
}


public class A {

	public A () {
		int N = sc.nextInt(), M = sc.nextInt(), B = sc.nextInt(); MOD = sc.nextInt();
		int [] A = sc.nextInts();

		int [][] F = new int [N][B+1];

		for (int n : rep(N))
			if (A[n] <= B)
				F[n][A[n]] = 1;

		int [] rB = req(B), rN = rep(N);
		for (int m : rep(1, M)) {
			int [][] G = new int [N][B+1];
			for (int b : rB) {
				int H = F[0][b];
				for (int j : rN) {
					int c = b + A[j];
					if (c <= B)
						G[j][c] = (G[j][c] + H) % MOD;
					if (j < N-1)
						H = (H + F[j+1][b]) % MOD;
				}
			}
			F = G;
		}

		long res = 0;
		for (int n : rN)
			for (int b : rB)
				res = (res + F[n][b]) % MOD;

		exit(res);
	}

	private static int MOD = (int) 1e9 + 7;
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [] req(int N) { return req(0, N); }
	private static int [] req(int S, int T) { return rep(S, T+1); }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			public String nextLine() { line = null; return readLine(); }
			public String [] nextStrings() { return split(nextLine()); }
			public int [] nextInts() {
				String [] L = nextStrings();
				int [] res = new int [L.length];
				for (int i = 0; i < L.length; ++i)
					res[i] = Integer.parseInt(L[i]);
				return res;
			}
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new A(); IOUtils.exit(); }
}


public class A {

	public A () {
		int N = sc.nextInt(), M = sc.nextInt(), B = sc.nextInt(); MOD = sc.nextInt();
		int [] A = sc.nextInts();

		int [][] F = new int [N][B+1];

		for (int n : rep(N))
			if (A[n] <= B)
				F[n][A[n]] = 1;

		for (@SuppressWarnings("unused") int m : rep(1, M)) {
			int [][] G = new int [N][B+1];
			for (int b = 0; b <= B; ++b) {
				int H = F[0][b];
				for (int j = 0; j < N; ++j) {
					int c = b + A[j];
					if (c <= B)
						G[j][c] = (G[j][c] + H) % MOD;
					if (j < N-1)
						H = (H + F[j+1][b]) % MOD;
				}
			}
			F = G;
		}

		long res = 0;
		for (int n : rep(N))
			for (int b : req(B))
				res = mod(res + F[n][b], MOD);

		exit(res);
	}

	private static int MOD = (int) 1e9 + 7;
	private static long mod(long x, long mod) { return ((x % mod) + mod) % mod; }
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [] req(int N) { return req(0, N); }
	private static int [] req(int S, int T) { return rep(S, T+1); }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			public String nextLine() { line = null; return readLine(); }
			public String [] nextStrings() { return split(nextLine()); }
			public int [] nextInts() {
				String [] L = nextStrings();
				int [] res = new int [L.length];
				for (int i = 0; i < L.length; ++i)
					res[i] = Integer.parseInt(L[i]);
				return res;
			}
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new A(); IOUtils.exit(); }
}


/*
 * Problem: From a given string, can you remove a contiguous set of letters and get CODEFORCES?
 *
 * Solution: Concatenate every non-overlapping prefix/suffix pair, including the empty prefix and suffix, and see if you get the result
 */

public class A {

	public A () {
		String S = sc.next();
		int N = S.length();

		for (int j : req(N))
			for (int i : req(j)) {
				String T = S.substring(0, i) + S.substring(j, N);
				if (T.equals("CODEFORCES"))
					exit("YES");
			}

		exit("NO");
	}

	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [] req(int N) { return req(0, N); }
	private static int [] req(int S, int T) { return rep(S, T+1); }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new A(); IOUtils.exit(); }
}


public class A {

	public A () {
		int N = sc.nextInt(), M = sc.nextInt(), B = sc.nextInt(); MOD = sc.nextInt();
		int [] A = sc.nextInts();

		long [][] F = new long [N][B+1];

		for (int n : rep(N))
			if (A[n] <= B)
				F[n][A[n]] = 1;

		int [] rB = req(B), rN = rep(N);
		for (@SuppressWarnings("unused") int m : rep(1, M)) {
			long [][] G = new long [N][B+1];
			for (int b : rB) {
				long H = F[0][b];
				for (int j : rN) {
					int c = b + A[j];
					if (c <= B)
						G[j][c] = mod(G[j][c] + H, MOD);
					if (j < N-1)
						H = mod(H + F[j+1][b], MOD);
				}
			}
			F = G;
		}

		long res = 0;
		for (int n : rep(N))
			for (int b : req(B))
				res = mod(res + F[n][b], MOD);

		exit(res);
	}

	private static int MOD = (int) 1e9 + 7;
	private static long mod(long x, long mod) { return ((x % mod) + mod) % mod; }
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	private static int [] req(int N) { return req(0, N); }
	private static int [] req(int S, int T) { return rep(S, T+1); }
	////////////////////////////////////////////////////////////////////////////////////
	private final static IOUtils.MyScanner sc = new IOUtils.MyScanner();
	private static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }
	private static class IOUtils {
		public static class MyScanner {
			public String next() { newLine(); return line[index++]; }
			public int nextInt() { return Integer.parseInt(next()); }
			public String nextLine() { line = null; return readLine(); }
			public String [] nextStrings() { return split(nextLine()); }
			public int [] nextInts() {
				String [] L = nextStrings();
				int [] res = new int [L.length];
				for (int i = 0; i < L.length; ++i)
					res[i] = Integer.parseInt(L[i]);
				return res;
			}
			//////////////////////////////////////////////
			private boolean eol() { return index == line.length; }
			private String readLine() {
				try {
					return r.readLine();
				} catch (Exception e) {
					throw new Error (e);
				}
			}
			private final java.io.BufferedReader r;
			private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
			private MyScanner (java.io.BufferedReader r) {
				try {
					this.r = r;
					while (!r.ready())
						Thread.sleep(1);
					start();
				} catch (Exception e) {
					throw new Error(e);
				}
			}
			private String [] line;
			private int index;
			private void newLine() {
				if (line == null || eol()) {
					line = split(readLine());
					index = 0;
				}
			}
			private String [] split(String s) { return s.length() > 0 ? s.split(" ") : new String [0]; }
		}
		private static String build(Object o, Object ... A) { return buildDelim(" ", o, A); }
		private static String buildDelim(String delim, Object o, Object ... A) {
			StringBuilder b = new StringBuilder();
			append(b, o, delim);
			for (Object p : A)
				append(b, p, delim);
			return b.substring(delim.length());
		}
		//////////////////////////////////////////////////////////////////////////////////
		private static void start() { if (t == 0) t = millis(); }
		private static void append(StringBuilder b, Object o, String delim) {
			if (o.getClass().isArray()) {
				int len = java.lang.reflect.Array.getLength(o);
				for (int i = 0; i < len; ++i)
					append(b, java.lang.reflect.Array.get(o, i), delim);
			} else if (o instanceof Iterable<?>)
				for (Object p : (Iterable<?>) o)
					append(b, p, delim);
			else {
				if (o instanceof Double)
					o = new java.text.DecimalFormat("#.############").format(o);
				b.append(delim).append(o);
			}
		}
		private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);
		private static void print(Object o, Object ... A) { pw.println(build(o, A)); }
		private static void err(Object o, Object ... A) { System.err.println(build(o, A)); }
		private static void exit() {
			IOUtils.pw.close();
			System.out.flush();
			err("------------------");
			err(IOUtils.time());
			System.exit(0);
		}
		private static long t;
		private static long millis() { return System.currentTimeMillis(); }
		private static String time() { return "Time: " + (millis() - t) / 1000.0; }
	}
	public static void main (String[] args) { new A(); IOUtils.exit(); }
}