#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int visited[100005],c[100005];
list<int> adj[100005];

bool dfs(int v, int cl)
{
    list<int>::iterator it;

    visited[v] = 1;
    if(c[v]!=cl)
        return 0;

    for(it = adj[v].begin(); it!=adj[v].end(); it++)
    {
        if(visited[*it]==0)
        {
            if(dfs(*it,cl)==0)
                return 0;
        }
    }
    return 1;
}

int main()
{
    freopen("input.txt","r",stdin);
    int i,n,u[100005],v[100005],v1=-1,v2=-1,flag1=1,flag2=1;
    list<int>::iterator it;

    cin>>n;
    for(i=1;i<=n-1;i++)
    {
        cin>>u[i]>>v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }

    for(i=1;i<=n;i++)
        cin>>c[i];

    for(i=1;i<=n-1;i++)
    {
        if(c[u[i]] != c[v[i]])
        {
            v1 = u[i]; v2 = v[i];
            break;
        }
    }

    for(it = adj[v1].begin(); it!=adj[v1].end(); it++)
    if(dfs(*it,c[*it])==0)
    {
        flag1 = 0; break;
    }

    for(it = adj[v2].begin(); it!=adj[v2].end(); it++)
    if(dfs(*it,c[*it])==0)
    {
        flag2 = 0; break;
    }

    if(v1==-1 && v2==-1)
        cout<<"YES"<<endl<<"1"<<endl;

    else if(flag1==0 && flag2==0)
        cout<<"NO"<<endl;

    else if(flag1==1)
        cout<<"YES"<<endl<<v1<<endl;

    else
        cout<<"YES"<<endl<<v2<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int visited[100005],c[100005];
list<int> adj[100005];

bool dfs(int v, int cl)
{
    //cout<<v<<" "<<cl<<endl;
    list<int>::iterator it;
//cout<<cl<<c[v]<<v<<"##########"<<endl;
    visited[v] = 1;
    if(c[v]!=cl)
       {

           return 0;
       }

    for(it = adj[v].begin(); it!=adj[v].end(); it++)
    {
        if(visited[*it]==0)
        {
            visited[*it]=1;
            if(dfs(*it,cl)==0)
                return 0;
        }
    }
    return 1;
}

int main()
{
    freopen("input.txt","r",stdin);
    int i,n,u[100005],v[100005],v1=-1,v2=-1,flag1=1,flag2=1;
    list<int>::iterator it;

    cin>>n;
    for(i=1;i<=n-1;i++)
    {
        cin>>u[i]>>v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }

    for(i=1;i<=n;i++)
        cin>>c[i];

    for(i=1;i<=n-1;i++)
    {
        if(c[u[i]] != c[v[i]])
        {
            v1 = u[i]; v2 = v[i];
            break;
        }
    }
    //cout<<v1<<" "<<v2<<endl;
    memset(visited,0,sizeof(visited));
    for(it = adj[v1].begin(); it!=adj[v1].end(); it++)
    {
        visited[v1]=1;
        //cout<<*it<<" * "<<c[*it]<<endl;
        if(dfs(*it,c[*it])==0)
        {
            flag1 = 0; break;
        }
    }

//cout<<"*"<<endl;
    memset(visited,0,sizeof(visited));
    for(it = adj[v2].begin(); it!=adj[v2].end(); it++)
    {
        visited[v2] = 1;
        if(dfs(*it,c[*it])==0)
        {
            flag2 = 0; break;
        }

    }

    if(v1==-1 && v2==-1)
        cout<<"YES"<<endl<<"1"<<endl;

    else if(flag1==0 && flag2==0)
        cout<<"NO"<<endl;

    else if(flag1==1)
        cout<<"YES"<<endl<<v1<<endl;

    else
        cout<<"YES"<<endl<<v2<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int visited[100005],c[100005];
list<int> adj[100005];

bool dfs(int v, int cl)
{
    list<int>::iterator it;

    visited[v] = 1;
    if(c[v]!=cl)
        return 0;

    for(it = adj[v].begin(); it!=adj[v].end(); it++)
    {
        if(visited[*it]==0)
        {
            if(dfs(*it,cl)==0)
                return 0;
        }
    }
    return 1;
}

int main()
{
    int i,n,u[100005],v[100005],v1=-1,v2=-1,flag1=1,flag2=1;
    list<int>::iterator it;

    cin>>n;
    for(i=1;i<=n-1;i++)
    {
        cin>>u[i]>>v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }

    for(i=1;i<=n;i++)
        cin>>c[i];

    for(i=1;i<=n-1;i++)
    {
        if(c[u[i]] != c[v[i]])
        {
            v1 = u[i]; v2 = v[i];
            break;
        }
    }

    for(it = adj[v1].begin(); it!=adj[v1].end(); it++)
    if(dfs(*it,c[*it])==0)
    {
        flag1 = 0; break;
    }

    for(it = adj[v2].begin(); it!=adj[v2].end(); it++)
    if(dfs(*it,c[*it])==0)
    {
        flag2 = 0; break;
    }

    if(v1==-1 && v2==-1)
        cout<<"YES"<<endl<<"1"<<endl;

    else if(flag1==0 && flag2==0)
        cout<<"NO"<<endl;

    else if(flag1==1)
        cout<<"YES"<<endl<<v1<<endl;

    else
        cout<<"YES"<<endl<<v2<<endl;

    return 0;
}


/*
 @resources: codeforces
 @date: 2017-2-2
 @author: QuanQqqqq
 @algorithm:
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>

#define maxn 300005
#define INF 0x3f3f3f
#define ll long long

using namespace std;

struct tree{
    int color;
    vector<int> v;
}num[maxn];

int n,ans,root,used[maxn],tt[maxn];
bool mark;
int judge;

void dfs1(int v,int last){
    tt[v] = 1;
    if(last != -1 && num[v].color != last){
        judge = 0;
        return;
    }
    int temp;
    for(int i = 0;i < num[v].v.size();i++){
        if(!tt[num[v].v[i]]){
            temp = last;
            if(last == -1){
                last = num[num[v].v[i]].color;

            }
            dfs1(num[v].v[i],last);
            last = temp;
        }
    }
}

void dfs(int v,int li,int last){
    used[v] = 1;
    if(num[v].color != last){
        memset(tt,0,sizeof(tt));
        tt[v] = true;
        judge = 1;
        ans = v;
        dfs1(root,num[root].color);
        dfs1(v,-1);
        if(judge == 0){
            memset(tt,0,sizeof(tt));
            ans = li;
            judge = 1;
            tt[last] = true;
            dfs1(root,num[root].color);
            dfs1(v,num[v].color);
        }
        return;
    }
    if(judge == -1)
        for(int i = 0;i < num[v].v.size();i++){
            if(!used[num[v].v[i]])
                dfs(num[v].v[i],v,num[v].color);
        }
}

int main(){
    int a,b,color,last;
    mark = true;
    judge = -1;
    scanf("%d",&n);
    for(int i = 0;i < n - 1;i++){
        scanf("%d %d",&a,&b);
        num[a].v.push_back(b);
        num[b].v.push_back(a);
    }
    last = -1;
    for(int i = 1;i <= n;i++){
        scanf("%d",&color);
        if(last != -1 && last != color)
            mark = false;
        last = color;
        num[i].color = color;
    }
    if(mark){
        judge = 1;
        ans = 1;
    } else {
        for(int i = 1;i <= n;i++){
            if(num[i].v.size() == 1){
                root = i;
                dfs(i,0,num[i].color);
                break;
            }
        }
    }
    judge == 1 ? printf("YES\n%d\n",ans) : printf("NO\n");
}

/*
 4
 1 2
 2 4
 2 5
 1 3
 1 2 1 4 5
*/


/*
 @resources: codeforces
 @date: 2017-2-2
 @author: QuanQqqqq
 @algorithm:
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>

#define maxn 300005
#define INF 0x3f3f3f
#define ll long long

using namespace std;

struct tree{
    int color;
    vector<int> v;
}num[maxn];

int n,ans,root,used[maxn],tt[maxn];
bool mark;
int judge;

void dfs1(int v,int last){
    tt[v] = 1;
    if(last != -1 && num[v].color != last){
        judge = 0;
        return;
    }
    int temp;
    for(int i = 0;i < num[v].v.size();i++){
        if(!tt[num[v].v[i]]){
            temp = last;
            if(last == -1){
                last = num[num[v].v[i]].color;
            }
            dfs1(num[v].v[i],last);
            last = temp;
        }
    }
}

void dfs(int v,int li,int last){
    used[v] = 1;
    if(num[v].color != last){
        memset(tt,0,sizeof(tt));
        tt[v] = true;
        judge = 1;
        ans = v;        if(v != root)
            dfs1(root,num[root].color);
        dfs1(v,-1);
        if(judge == 0){
            memset(tt,0,sizeof(tt));
            ans = li;
            judge = 1;
            tt[li] = true;
            if(last == root){
                dfs1(root,-1);
            } else {
                dfs1(root,num[root].color);
                dfs1(v,num[v].color);
            }
        }
        return;
    }
    if(judge == -1)
        for(int i = 0;i < num[v].v.size();i++){
            if(!used[num[v].v[i]])
                dfs(num[v].v[i],v,num[v].color);
        }
}

int main(){
    int a,b,color,last;
    mark = true;
    judge = -1;
    scanf("%d",&n);
    for(int i = 0;i < n - 1;i++){
        scanf("%d %d",&a,&b);
        num[a].v.push_back(b);
        num[b].v.push_back(a);
    }
    last = -1;
    for(int i = 1;i <= n;i++){
        scanf("%d",&color);
        if(last != -1 && last != color)
            mark = false;
        last = color;
        num[i].color = color;
    }
    if(mark){
        judge = 1;
        ans = 1;
    } else {
        for(int i = 1;i <= n;i++){
            if(num[i].v.size() == 1){
                root = i;
                dfs(i,0,num[i].color);
                break;
            }
        }
    }
    if(judge == 1) {
        printf("YES\n%d\n",ans);
    } else {
        printf("NO\n");
    }
}

/*
 4
 1 2
 2 4
 2 5
 1 3
 1 2 1 4 5
*/


/*
 @resources: codeforces
 @date: 2017-2-2
 @author: QuanQqqqq
 @algorithm:
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>

#define maxn 300005
#define INF 0x3f3f3f
#define ll long long

using namespace std;

struct tree{
    int color;
    vector<int> v;
}num[maxn];

int n,ans,root,used[maxn],tt[maxn];
bool mark;
int judge;

void dfs1(int v,int last){
    tt[v] = 1;
    if(last != -1 && num[v].color != last){
        judge = 0;
        return;
    }
    int temp;
    for(int i = 0;i < num[v].v.size();i++){
        if(!tt[num[v].v[i]]){
            temp = last;
            if(last == -1){
                last = num[num[v].v[i]].color;
            }
            dfs1(num[v].v[i],last);
            last = temp;
        }
    }
}

void dfs(int v,int li,int last){
    used[v] = 1;
    if(num[v].color != last){
        memset(tt,0,sizeof(tt));
        tt[v] = true;
        judge = 1;
        ans = v;        if(v != root)
            dfs1(root,num[root].color);
        dfs1(v,-1);
        if(judge == 0){
            memset(tt,0,sizeof(tt));
            ans = li;
            judge = 1;
            tt[li] = true;
            if(last == root){
                dfs1(root,-1);
            } else {
                dfs1(root,num[root].color);
                dfs1(v,num[v].color);
            }
        }
        return;
    }
    if(judge == -1)
        for(int i = 0;i < num[v].v.size();i++){
            if(!used[num[v].v[i]])
                dfs(num[v].v[i],v,num[v].color);
        }
}

int main(){
    int a,b,color,last;
    mark = true;
    judge = -1;
    scanf("%d",&n);
    for(int i = 0;i < n - 1;i++){
        scanf("%d %d",&a,&b);
        num[a].v.push_back(b);
        num[b].v.push_back(a);
    }
    last = -1;
    for(int i = 1;i <= n;i++){
        scanf("%d",&color);
        if(last != -1 && last != color)
            mark = false;
        last = color;
        num[i].color = color;
    }
    if(mark){
        judge = 1;
        ans = 1;
    } else {
        for(int i = 1;i <= n;i++){
            if(num[i].v.size() == 1){
                root = i;
                dfs(i,0,num[i].color);
                break;
            }
        }
    }
    if(judge == 1) {
        memset(tt,0,sizeof(tt));
        tt[ans] = 1;
        if(!mark){
            if(ans == root){
                dfs1(root,-1);
            } else {
                dfs1(root,num[root].color);
                dfs1(ans,-1);
            }
        }
        if(judge == 1){
            printf("YES\n%d\n",ans);
        }
        else {
            printf("NO\n");
        }
    } else {
        printf("NO\n");
    }
}

/*
 4
 1 2
 2 4
 2 5
 1 3
 1 2 1 4 5
 */


/*
 @resources: codeforces
 @date: 2017-2-2
 @author: QuanQqqqq
 @algorithm:
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>

#define maxn 300005
#define INF 0x3f3f3f
#define ll long long

using namespace std;

struct tree{
    int color;
    vector<int> v;
}num[maxn];

int n,ans,root,used[maxn],tt[maxn];
bool mark;
int judge;

void dfs1(int v,int last){
    tt[v] = 1;
    if(last != -1 && num[v].color != last){
        judge = 0;
        return;
    }
    int temp;
    for(int i = 0;i < num[v].v.size();i++){
        if(!tt[num[v].v[i]]){
            temp = last;
            if(last == -1){
                last = num[num[v].v[i]].color;
            }
            dfs1(num[v].v[i],last);
            last = temp;
        }
    }
}

void dfs(int v,int li,int last){
    used[v] = 1;
    if(num[v].color != last){
        memset(tt,0,sizeof(tt));
        tt[v] = true;
        judge = 1;
        ans = v;        if(v != root)
            dfs1(root,num[root].color);
        dfs1(v,-1);
        if(judge == 0){
            memset(tt,0,sizeof(tt));
            ans = li;
            judge = 1;
            tt[li] = true;
            if(last == root){
                dfs1(root,-1);
            } else {
                dfs1(root,num[root].color);
                dfs1(v,num[v].color);
            }
        }
        return;
    }
    if(judge == -1)
        for(int i = 0;i < num[v].v.size();i++){
            if(!used[num[v].v[i]])
                dfs(num[v].v[i],v,num[v].color);
        }
}

int main(){
    int a,b,color,last;
    mark = true;
    judge = -1;
    scanf("%d",&n);
    for(int i = 0;i < n - 1;i++){
        scanf("%d %d",&a,&b);
        num[a].v.push_back(b);
        num[b].v.push_back(a);
    }
    last = -1;
    for(int i = 1;i <= n;i++){
        scanf("%d",&color);
        if(last != -1 && last != color)
            mark = false;
        last = color;
        num[i].color = color;
    }
    if(mark){
        judge = 1;
        ans = 1;
    } else {
        for(int i = 1;i <= n;i++){
            if(num[i].v.size() == 1){
                root = i;
                dfs(i,0,num[i].color);
                break;
            }
        }
    }
    if(judge == 1) {
        memset(tt,0,sizeof(tt));
        tt[ans] = 1;
        if(!mark){
            if(ans == root){
                dfs1(root,-1);
            } else {
                dfs1(root,num[root].color);
                dfs1(ans,-1);
            }
        }
        if(judge == 1){
            printf("YES\n%d\n",ans);
        }
        else {
            printf("NO\n");
        }
    } else {
        printf("NO\n");
    }
}

/*
 4
 1 2
 2 4
 2 5
 1 3
 1 2 1 4 5
*/


/*
 @resources: codeforces
 @date: 2017-2-2
 @author: QuanQqqqq
 @algorithm:
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>

#define maxn 300005
#define INF 0x3f3f3f
#define ll long long

using namespace std;

struct tree{
    int color;
    vector<int> v;
}num[maxn];

int n,ans,root,used[maxn],tt[maxn];
bool mark;
int judge;

void dfs1(int v,int last){
    tt[v] = 1;
    if(last != -1 && num[v].color != last){
        judge = 0;
        return;
    }
    int temp;
    for(int i = 0;i < num[v].v.size();i++){
        if(!tt[num[v].v[i]]){
            temp = last;
            if(last == -1){
                last = num[num[v].v[i]].color;
            }
            dfs1(num[v].v[i],last);
            last = temp;
        }
    }
}

void dfs(int v,int li,int last){
    used[v] = 1;
    if(num[v].color != last){
        memset(tt,0,sizeof(tt));
        tt[v] = true;
        judge = 1;
        ans = v;
        if(v != root)
            dfs1(root,num[root].color);
        dfs1(v,-1);
        if(judge == 0){
            memset(tt,0,sizeof(tt));
            ans = li;
            judge = 1;
            tt[last] = true;
            if(last == root){
                dfs1(root,-1);
            } else {
                dfs1(root,num[root].color);
                dfs1(v,num[v].color);
            }
        }
        return;
    }
    if(judge == -1)
        for(int i = 0;i < num[v].v.size();i++){
            if(!used[num[v].v[i]])
                dfs(num[v].v[i],v,num[v].color);
        }
}

int main(){
    int a,b,color,last;
    mark = true;
    judge = -1;
    scanf("%d",&n);
    for(int i = 0;i < n - 1;i++){
        scanf("%d %d",&a,&b);
        num[a].v.push_back(b);
        num[b].v.push_back(a);
    }
    last = -1;
    for(int i = 1;i <= n;i++){
        scanf("%d",&color);
        if(last != -1 && last != color)
            mark = false;
        last = color;
        num[i].color = color;
    }
    if(mark){
        judge = 1;
        ans = 1;
    } else {
        for(int i = 1;i <= n;i++){
            if(num[i].v.size() == 1){
                root = i;
                dfs(i,0,num[i].color);
                break;
            }
        }
    }
    if(judge == 1) {
        memset(tt,0,sizeof(tt));
        tt[ans] = 1;
        if(!mark){
            if(ans == root){
                dfs1(root,-1);
            } else {
                dfs1(root,num[root].color);
                dfs1(ans,-1);
            }
        }
        if(judge == 1){
            printf("YES\n%d\n",ans);
        }
        else {
            printf("NO\n");
        }
    } else {
        printf("NO\n");
    }
}

/*
 4
 1 2
 2 4
 2 5
 1 3
 1 2 1 4 5
*/


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x %mod;
    x=x*x %mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int n;
cin>>n;
vector<pair<int,int>>e;
rep(i,0,n-2){
  int u,v;
  cin>>u>>v;
 e.push_back({u,v});
}
vi c(n+1);
rep(i,1,n) cin>>c[i];
int b=0;
vi deg(n+1);
for(int i=0;i<n-1;++i){
  if(c[e[i].first]!=c[e[i].second]){
      deg[e[i].first]++;
      deg[e[i].second]++;
  }
}
int t=1;
t=max(1,max_element(all(deg))-deg.begin());
ll sum=0;
for(int i=1;i<=n;++i){
if(deg[i]<=1) { sum+=deg[i]; continue; }
++b;
t=i;
}
if((deg[t]>1&&deg[t]!=sum)||(deg[t]==1&&deg[t]!=sum-1)) b=1<<10;
if(b<=1) {
  cout<<"YES\n";
 cout<<t;
}
else cout<<"NO";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>

using namespace std;

#define MAX_BOARD 210
#define MAX_CAP 40050
#define INF 1000000000
int n;
int a,b;
int h[MAX_BOARD];
int dp[MAX_BOARD][MAX_CAP][2];

int rec(int board, int cap, int taken);

int main() {
    scanf("%d%d%d",&n,&a,&b);
    int total = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d",&h[i]);
        total += h[i];
    }
    memset(dp,-1,sizeof dp);
    int res = INF;
    for (int i = 0; i <= a; i++){
        int val = rec(0,i,0);
        if (val >= INF) continue;
        if (total - i <= b) {
            res = min(res,val);
        }
    }
    printf("%d\n",res);
    return 0;
}

int rec(int board, int cap, int taken) {
    if (dp[board][cap][taken] != -1) return dp[board][cap][taken];
    int &res = dp[board][cap][taken];
    //advance to next board
    res = INF;
    if (board >= n) {
        if (cap == 0) res = 0;
        else res = INF;
    }
    else {
        //take board
        if (cap - h[board] >= 0) {
            int additionCost = 0;
            //assert(board > 0 || taken);
            if (board > 0 && !taken) additionCost = h[board]+h[board-1];
            res = min(res,additionCost + rec(board+1,cap-h[board],1));
        }  {//don't take board
            int additionCost = 0;
            //assert(board > 0 || taken);
            if (board > 0 && taken) additionCost = h[board]+h[board-1];
            res = min(res,additionCost + rec(board+1,cap,0));
        }

    }
    return res;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>

using namespace std;

#define MAX_BOARD 210
#define MAX_CAP 40050
#define INF 1000000000
int n;
int a,b;
int h[MAX_BOARD];
int dp[MAX_BOARD][MAX_CAP][2];

int rec(int board, int cap, int taken);

int main() {
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d%d",&n,&a,&b);
    int total = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d",&h[i]);
        total += h[i];
    }
    memset(dp,-1,sizeof dp);
    int res = INF;
    for (int i = 0; i <= a; i++){
        int val = rec(0,i,0);
        if (val >= INF) continue;
        if (total - i <= b) {
            res = min(res,val);
        }
    }
    printf("%d\n",res >= INF ? -1 : 0);
    return 0;
}

int rec(int board, int cap, int taken) {
    if (dp[board][cap][taken] != -1) return dp[board][cap][taken];
    int &res = dp[board][cap][taken];
    //advance to next board
    res = INF;
    if (board >= n) {
        if (cap == 0) res = 0;
        else res = INF;
    }
    else {
        //take board
        if (cap - h[board] >= 0) {
            int additionCost = 0;
            //assert(board > 0 || taken);
            if (board > 0 && taken == 0) additionCost = min(h[board],h[board-1]);
            res = min(res,additionCost + rec(board+1,cap-h[board],1));
        }  {//don't take board
            int additionCost = 0;
            //assert(board > 0 || taken);
            if (board > 0 && taken == 1) additionCost = min(h[board],h[board-1]);
            res = min(res,additionCost + rec(board+1,cap,0));
        }

    }
    return res;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>

using namespace std;

#define MAX_BOARD 210
#define MAX_CAP 40050
#define INF 1000000000
int n;
int a,b;
int h[MAX_BOARD];
int dp[MAX_BOARD][MAX_CAP][2];

int rec(int board, int cap, int taken);

int main() {
    scanf("%d%d%d",&n,&a,&b);
    int total = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d",&h[i]);
        total += h[i];
    }
    memset(dp,-1,sizeof dp);
    int res = INF;
    for (int i = 0; i <= a; i++){
        int val = rec(0,i,0);
        if (val >= INF) continue;
        if (total - i <= b) {
            res = min(res,val);
        }
    }
    printf("%d\n",res);
    return 0;
}

int rec(int board, int cap, int taken) {
    if (dp[board][cap][taken] != -1) return dp[board][cap][taken];
    int &res = dp[board][cap][taken];
    //advance to next board
    res = INF;
    if (board >= n) {
        if (cap == 0) res = 0;
        else res = INF;
    }
    else {
        //take board
        if (cap - h[board] >= 0) {
            int additionCost = 0;
            //assert(board > 0 || taken);
            if (board > 0 && !taken) additionCost = h[board]+h[board-1];
            res = min(res,additionCost + rec(board+1,cap-h[board],1));
        } else { //don't take board
            int additionCost = 0;
            //assert(board > 0 || taken);
            if (board > 0 && taken) additionCost = h[board]+h[board-1];
            res = min(res,additionCost + rec(board+1,cap,0));
        }

    }
    return res;
}


/*
 * File:      main.cpp
 * Author:    Hrayr [HarHro94]
 * Problem:
 * IDE:       Visual C++ 2012
 */
//#pragma comment(linker, "/STACK:67108864")
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;

typedef long double LD;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

const int INF = 1000000000;
const int N = 207;
const int A = 40007;
int n, a, b, h[N], sum[N], dp[N][A][2];

int main()
{
#ifdef harhro94
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++i)
    {
        cin >> h[i];
        sum[i] = h[i] + sum[i - 1];
    }
    fill(dp[0][0], dp[0][0] + N * A * 2, INF);
    if (a >= h[1])
    {
        dp[1][h[1]][0] = 0;
    }
    if (b >= h[1])
    {
        dp[1][0][1] = 0;
    }
    for (int i = 2; i <= n; ++i)
    {
        for (int aa = 0; aa <= a; ++aa)
        {
            int bb = sum[i - 1] - aa;

            if (aa + h[i] <= a)
            {
                dp[i][aa + h[i]][0] = min(dp[i][aa + h[i]][0], dp[i - 1][aa][0]);
                dp[i][aa + h[i]][0] = min(dp[i][aa + h[i]][0], dp[i - 1][aa][1] + min(h[i], h[i - 1]));
            }

            if (bb + h[i] <= b)
            {
                dp[i][aa][1] = min(dp[i][aa][1], dp[i - 1][aa][0] + min(h[i], h[i - 1]));
                dp[i][aa][1] = min(dp[i][aa][1], dp[i - 1][aa][1]);
            }
        }
    }
    int ans = INF;
    for (int aa = 0; aa <= a; ++aa)
    {
        ans = min(ans, dp[n][aa][0]);
        ans = min(ans, dp[n][aa][1]);
    }
    if (ans == INF)
    {
        ans = -1;
    }
    cout << ans << endl;

#ifdef harhro94
    cerr << fixed << setprecision(3) << "\nExecution time = " << clock() / 1000.0 << "s\n";
#endif
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
using namespace std;

//{{{
//-----------------------By cylixstar-----------------------//
#define rep(i, n) for (int n_##__LINE__= (n), i = 0; i < n_##__LINE__; ++i)
#define rep2(i, f, t) for (int i = f; i <= t; ++i)
#define all(c) (c).begin(), (c).end()
//}}}

const int maxn = 200 + 10;
const int maxA = 40000 + 10;
int dp[2][maxA][2];
int n, a, b;
int h[maxn];

void checkMin(int& x, int v) {
  if (x < 0 || x > v) {
    x = v;
  }
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d%d%d", &n, &a, &b);
  int totArea = 0;
  rep(i, n) {
    scanf("%d", h + i);
    totArea += h[i];
  }
  if (a + b < totArea) {
    puts("-1");
    return 0;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][h[0]][0] = 0;
  dp[0][0][1] = 0;
  int cur = 0, next = 1;
  totArea = h[0];
  int B;
  rep2(i,1, n - 1) {
    memset(dp[next], -1,sizeof(dp[next]));
    rep2(A, 0, a) {
      B = totArea - A;
      if (dp[cur][A][0] >= 0) {
        if (A + h[i] <= a) {
          checkMin(dp[next][A + h[i]][0], dp[cur][A][0]);
        }
        if (B + h[i] <= b) {
          checkMin(dp[next][A][1], dp[cur][A][0] + min(h[i], h[i - 1]));
        }
      }
      if (dp[cur][A][1] >= 0) {
        //printf("See %d %d %d\n", cur, A, B);
        if (A + h[i] <= a) {
          checkMin(dp[next][A + h[i]][0], dp[cur][A][1] + min(h[i], h[i - 1]));
        }
        if (B + h[i] <= b) {
          checkMin(dp[next][A][1], dp[cur][A][1]);
        }
      }
    }
    totArea += h[i];
    swap(cur, next);
  }
  int best = -1;
  rep2(A, 0, a) {
    if (dp[cur][A][0] >= 0) {
      checkMin(best, dp[cur][A][0]);
    }
    if (dp[cur][A][1] >= 0) {
      checkMin(best, dp[cur][A][1]);
    }
  }
  printf("%d\n", best);
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
using namespace std;

//{{{
//-----------------------By cylixstar-----------------------//
#define rep(i, n) for (int n_##__LINE__= (n), i = 0; i < n_##__LINE__; ++i)
#define rep2(i, f, t) for (int i = f; i <= t; ++i)
#define all(c) (c).begin(), (c).end()
//}}}

const int maxn = 200 + 10;
const int maxA = 40000 + 10;
int dp[2][maxA][2];
int n, a, b;
int h[maxn];

void checkMin(int& x, int v) {
  if (x < 0 || x > v) {
    x = v;
  }
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d%d%d", &n, &a, &b);
  int totArea = 0;
  rep(i, n) {
    scanf("%d", h + i);
    totArea += h[i];
  }
  if (a + b < totArea) {
    puts("-1");
    return 0;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][h[0]][0] = 0;
  dp[0][0][1] = 0;
  int cur = 0, next = 1;
  totArea = h[0];
  int B;
  rep2(i,1, n - 1) {
    memset(dp[next], -1,sizeof(dp[next]));
    rep2(A, 0, a) {
      B = totArea - A;
      if (dp[cur][A][0] >= 0) {
        if (A + h[i] <= a) {
          checkMin(dp[next][A + h[i]][0], dp[cur][A][0]);
        }
        if (B + h[i] <= b) {
          checkMin(dp[next][A][1], dp[cur][A][0] + min(h[i], h[i - 1]));
        }
      }
      if (dp[cur][A][1] >= 0) {
        //printf("See %d %d %d\n", cur, A, B);
        if (A + h[i] <= a) {
          checkMin(dp[next][A + h[i]][0], dp[cur][A][1] + min(h[i], h[i - 1]));
        }
        if (B + h[i] <= b) {
          checkMin(dp[next][A][1], dp[cur][A][1]);
        }
      }
    }
    totArea += h[i];
    swap(cur, next);
  }
  int best = -1;
  rep2(A, 0, a) {
    B = totArea - A;
    if (B < 0 || B > b) continue;
    if (dp[cur][A][0] >= 0) {
      checkMin(best, dp[cur][A][0]);
    }
    if (dp[cur][A][1] >= 0) {
      checkMin(best, dp[cur][A][1]);
    }
  }
  printf("%d\n", best);
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
using namespace std;

//{{{
//-----------------------By cylixstar-----------------------//
#define rep(i, n) for (int n_##__LINE__= (n), i = 0; i < n_##__LINE__; ++i)
#define rep2(i, f, t) for (int i = f; i <= t; ++i)
#define all(c) (c).begin(), (c).end()
//}}}

const int maxn = 200 + 10;
const int maxA = 40000 + 10;
int dp[2][maxA][2];
int n, a, b;
int h[maxn];

void checkMin(int& x, int v) {
  if (x < 0 || x > v) {
    x = v;
  }
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d%d%d", &n, &a, &b);
  int totArea = 0;
  rep(i, n) {
    scanf("%d", h + i);
    totArea += h[i];
  }
  if (a + b > totArea) {
    puts("-1");
    return 0;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][h[0]][0] = 0;
  dp[0][0][1] = 0;
  int cur = 0, next = 1;
  totArea = h[0];
  int B;
  rep2(i,1, n - 1) {
    memset(dp[next], -1,sizeof(dp[next]));
    rep2(A, 0, a) {
      B = totArea - A;
      if (dp[cur][A][0] >= 0) {
        if (A + h[i] <= a) {
          checkMin(dp[next][A + h[i]][0], dp[cur][A][0]);
        }
        if (B + h[i] <= b) {
          checkMin(dp[next][A][1], dp[cur][A][0] + min(h[i], h[i - 1]));
        }
      }
      if (dp[cur][A][1] >= 0) {
        //printf("See %d %d %d\n", cur, A, B);
        if (A + h[i] <= a) {
          checkMin(dp[next][A + h[i]][0], dp[cur][A][1] + min(h[i], h[i - 1]));
        }
        if (B + h[i] <= b) {
          checkMin(dp[next][A][1], dp[cur][A][1]);
        }
      }
    }
    totArea += h[i];
    swap(cur, next);
  }
  int best = -1;
  rep2(A, 0, a) {
    if (dp[cur][A][0] >= 0) {
      checkMin(best, dp[cur][A][0]);
    }
    if (dp[cur][A][1] >= 0) {
      checkMin(best, dp[cur][A][1]);
    }
  }
  printf("%d\n", best);
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
using namespace std;

//{{{
//-----------------------By cylixstar-----------------------//
#define rep(i, n) for (int n_##__LINE__= (n), i = 0; i < n_##__LINE__; ++i)
#define rep2(i, f, t) for (int i = f; i <= t; ++i)
#define all(c) (c).begin(), (c).end()
//}}}

const int maxn = 200 + 10;
const int maxA = 40000 + 10;
int dp[2][maxA][2];
int n, a, b;
int h[maxn];

void checkMin(int& x, int v) {
  if (x < 0 || x > v) {
    x = v;
  }
}

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  scanf("%d%d%d", &n, &a, &b);
  rep(i, n) {
    scanf("%d", h + i);
  }

  memset(dp, -1, sizeof(dp));
  dp[0][h[0]][0] = 0;
  dp[0][0][1] = 0;
  int cur = 0, next = 1;
  int totArea = h[0], B;
  rep2(i,1, n - 1) {
    memset(dp[next], -1,sizeof(dp[next]));
    rep2(A, 0, a) {
      B = totArea - A;
      if (dp[cur][A][0] >= 0) {
        if (A + h[i] <= a) {
          checkMin(dp[next][A + h[i]][0], dp[cur][A][0]);
        }
        if (B + h[i] <= b) {
          checkMin(dp[next][A][1], dp[cur][A][0] + min(h[i], h[i - 1]));
        }
      }
      if (dp[cur][A][1] >= 0) {
        //printf("See %d %d %d\n", cur, A, B);
        if (A + h[i] <= a) {
          checkMin(dp[next][A + h[i]][0], dp[cur][A][1] + min(h[i], h[i - 1]));
        }
        if (B + h[i] <= b) {
          checkMin(dp[next][A][1], dp[cur][A][1]);
        }
      }
    }
    totArea += h[i];
    swap(cur, next);
  }
  int best = -1;
  rep2(A, 0, a) {
    if (dp[cur][A][0] >= 0) {
      checkMin(best, dp[cur][A][0]);
    }
    if (dp[cur][A][1] >= 0) {
      checkMin(best, dp[cur][A][1]);
    }
  }
  printf("%d\n", best);
  return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <map>
#include <functional>
#include <string>
#include <iomanip>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <sstream>
//#pragma comment (linker, "/STACK:167177216")
using namespace std;
#define mems(A, val) memset(A, val, sizeof(A))
#define mp(a, b) make_pair(a, b)
#define all(B) (B).begin(), (B).end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define forit (it, coll) for(auto it = coll.begin(); it != coll.end(); ++it)
const int MAXN = 210;
const int MAX = 2147483647;
typedef long long LL;

int D[205][40005][2];
int fence[205];

int BigColor, SmallColor;
int n;

int rec(int i, int color, bool pokr, int unattractive, int anotherCollor)
{
	if (i == n) return 0;

	int plus = 0;
	int result = 100000000;
	if (fence[i] <= color)
	{
		if (!pokr && i > 0)
			plus = min(fence[i], fence[i - 1]);
		else
			plus = 0;
		if (D[i + 1][color - fence[i]][true] == -1) D[i + 1][color - fence[i]][true] = rec(i + 1, color - fence[i], true, unattractive + plus, anotherCollor);
		result = min(result, D[i + 1][color - fence[i]][true] + plus);
	}

	if (fence[i] <= anotherCollor)
	{
		if (pokr && i > 0)
			plus = min(fence[i], fence[i - 1]);
		else
			plus = 0;
		if (D[i + 1][color][false] == -1) D[i + 1][color][false] = rec(i + 1, color, false, unattractive + plus, anotherCollor - fence[i]);
		result = min(result, D[i + 1][color][false] + plus);
		}

	return D[i][color][pokr] = result;
}

int main() {
#ifdef MY_SOL
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif

	cin >> n;
	mems(D, -1);

	cin >> SmallColor >> BigColor;
	if (BigColor < SmallColor) swap(BigColor, SmallColor);

	for (int i = 0; i < n; i++)
		cin >> fence[i];

	int ans = rec(0, BigColor, false, 0, SmallColor);

	if (ans < 400005)
		cout << ans;
	else cout << -1;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <map>
#include <functional>
#include <string>
#include <iomanip>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <sstream>
//#pragma comment (linker, "/STACK:167177216")
using namespace std;
#define mems(A, val) memset(A, val, sizeof(A))
#define mp(a, b) make_pair(a, b)
#define all(B) (B).begin(), (B).end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define forit (it, coll) for(auto it = coll.begin(); it != coll.end(); ++it)
const int MAXN = 210;
const int MAX = 2147483647;
typedef long long LL;

int D[205][40005][2];
int fence[205];

int BigColor, SmallColor;
int n;

int rec(int i, int color, bool pokr, int unattractive, int anotherCollor)
{
	if (D[i][color][pokr] < unattractive)
		return 0;
	D[i][color][pokr] = unattractive;
	if (i == n) return 0;

	int plus = 0;
	if (fence[i] <= color)
	{
		if (!pokr && i > 0)
			plus = min(fence[i], fence[i - 1]);
		else
			plus = 0;
		if (D[i + 1][color - fence[i]][true] >= unattractive + plus) rec(i + 1, color - fence[i], true, unattractive + plus, anotherCollor);
	}

	if (fence[i] <= anotherCollor)
	{
		if (pokr && i > 0)
			plus = min(fence[i], fence[i - 1]);
		else
			plus = 0;
		if (D[i + 1][color][false] >= unattractive + plus) rec(i + 1, color, false, unattractive + plus, anotherCollor - fence[i]);
	}
}

int main() {
#ifdef MY_SOL
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif

	cin >> n;
	mems(D, 1);

	cin >> SmallColor >> BigColor;
	if (BigColor < SmallColor) swap(BigColor, SmallColor);

	for (int i = 0; i < n; i++)
		cin >> fence[i];

	rec(0, BigColor, false, 0, SmallColor);
	int ans = 400005;
	for (int i = 0; i < 40005; i++)
	{
		if (ans > D[n][i][0])
			ans = D[n][i][0];
		if (ans > D[n][i][1])
			ans = D[n][i][1];
	}

	if (ans != 400005)
		cout << ans;
	else cout << -1;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <map>
#include <functional>
#include <string>
#include <iomanip>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <sstream>
//#pragma comment (linker, "/STACK:167177216")
using namespace std;
#define mems(A, val) memset(A, val, sizeof(A))
#define mp(a, b) make_pair(a, b)
#define all(B) (B).begin(), (B).end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define forit (it, coll) for(auto it = coll.begin(); it != coll.end(); ++it)
const int MAXN = 210;
const int MAX = 2147483647;
typedef long long LL;

int D[205][40005][2];
int fence[205];

int BigColor, SmallColor;
int n;

int rec(int i, int color, bool pokr, int unattractive, int anotherCollor)
{
	if (i == n) return 0;

	int plus = 0;
	int result = 100000000;
	if (fence[i] <= color)
	{
		if (!pokr && i > 0)
			plus = min(fence[i], fence[i - 1]);
		else
			plus = 0;
		if (D[i + 1][color - fence[i]][true] == -1) D[i + 1][color - fence[i]][true] = rec(i + 1, color - fence[i], true, unattractive + plus, anotherCollor);
		result = min(result, D[i + 1][color - fence[i]][true] + plus);
	}

	if (fence[i] <= anotherCollor)
	{
		if (pokr && i > 0)
			plus = min(fence[i], fence[i - 1]);
		else
			plus = 0;
		if (D[i + 1][color][false] == -1) D[i + 1][color][false] = rec(i + 1, color, false, unattractive + plus, anotherCollor - fence[i]);
		result = min(result, D[i + 1][color][false] + plus);
		}

	return D[i][color][pokr] = result;
}

int main() {
#ifdef MY_SOL
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif

	cin >> n;
	mems(D, -1);

	cin >> SmallColor >> BigColor;
	if (BigColor < SmallColor) swap(BigColor, SmallColor);

	for (int i = 0; i < n; i++)
		cin >> fence[i];

	int ans = rec(0, BigColor, false, 0, SmallColor);

	if (ans < 400005)
		cout << ans;
	else cout << -1;

	return 0;
}


//
//  main.cpp
//  opencup
//
//  Created by Rodion Permin on 10/14/12.
//  Copyright (c) 2012 Rodion Permin. All rights reserved.
//

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <cstring>
#include <string>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define MP make_pair
#define all(v) (v).begin(), (v).end()
#define debug(x) //cerr << #x << ": " << (x) << endl;

const int INF = ((1 << 30) - 1);
const long long LLINF = (((1LL << 63) - 1LL));
const double eps = 1e-9;
const double PI = 3.14159265358979323846;

template<class T>
ostream& operator << (ostream& out, const vector<T>& v) {out << "["; for (int i = 0; i < v.size(); ++i) {
    if (i)
        out << ", ";
    out << v[i];
}; out << "]"; return out;}

int dp[200*200+1][200][2];

int main(int argc, const char * argv[]) {
//    freopen("/Users/permin/Documents/Olymp/opencup/opencup/input.txt", "r", stdin);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    vector<int> h(n);
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        debug(i);
    }
    cerr << "READ";
    int area = accumulate(all(h), 0);
    for (int i = 0; i <= area; ++i) {
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < 2; ++k)
                dp[i][j][k] = INF;
    }
    //vector<vector<vector<int> > > dp(area + 1, vector<vector<int> > (n + 1, vector<int> (2, INF)));
    dp[h[0]][0][0] = 0;
    dp[0][0][1] = 0;
    vector<int> p(h);
    for (int i = 1; i < n; ++i)
        p[i] += p[i - 1];
    for (int i = 1; i < n; ++i) {
        debug(i);
        for (int s = 0; s <= p[i]; ++s) {
            for (int col = 0; col < 2; ++col) {
                if (h[i] <= s && col == 0) {
                    dp[s][i][0] = min(dp[s][i][col], dp[s-h[i]][i - 1][0]);
                    dp[s][i][0] = min(dp[s][i][col], dp[s-h[i]][i - 1][1] + min(h[i-1],h[i]));
                }
                dp[s][i][1] = min(dp[s][i-1][1], dp[s][i-1][0] + min(h[i-1],h[i]));
            }
        }
    }
    int res = INF;
    for (int s = 0; s <= area; ++s) {
        if (s <= a && area - s <= b) {
            res = min(res, dp[s][n - 1][0]);
            res = min(res, dp[s][n - 1][1]);
        }
    }
    if (res >= INF - 2)
        res = -1;
    cout << res;
    return 0;
}


//
//  main.cpp
//  opencup
//
//  Created by Rodion Permin on 10/14/12.
//  Copyright (c) 2012 Rodion Permin. All rights reserved.
//

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <cstring>
#include <string>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define MP make_pair
#define all(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl;

const int INF = ((1 << 30) - 1);
const long long LLINF = (((1LL << 63) - 1LL));
const double eps = 1e-9;
const double PI = 3.14159265358979323846;

template<class T>
ostream& operator << (ostream& out, const vector<T>& v) {out << "["; for (int i = 0; i < v.size(); ++i) {
    if (i)
        out << ", ";
    out << v[i];
}; out << "]"; return out;}

int main(int argc, const char * argv[]) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    vector<int> h(n);
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; ++i)
        cin >> h[i];
    int area = accumulate(all(h), 0);
    vector<vector<vector<int> > > dp(area + 1, vector<vector<int> > (n + 1, vector<int> (2, INF)));
    dp[h[0]][0][0] = 0;
    dp[0][0][1] = 0;
    for (int i = 1; i < n; ++i) {
        for (int s = 0; s <= area; ++s) {
            for (int col = 0; col < 2; ++col) {
                if (h[i] <= s && col == 0) {
                    dp[s][i][0] = min(dp[s][i][col], dp[s-h[i]][i - 1][0]);
                    dp[s][i][0] = min(dp[s][i][col], dp[s-h[i]][i - 1][1] + min(h[i-1],h[i]));
                }
                dp[s][i][1] = min(dp[s][i-1][1], dp[s][i-1][0] + min(h[i-1],h[i]));
            }
        }
    }
    int res = INF;
    for (int s = 0; s <= area; ++s) {
        if (s <= a && area - s <= b) {
            res = min(res, dp[s][n - 1][0]);
            res = min(res, dp[s][n - 1][1]);
        }
    }
    if (res >= INF - 2)
        res = -1;
    cout << res;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz size()
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define out(x) cout << (x);

typedef long double ld;
template <class _T> inline _T sqr(const _T& x) { return x * x; }
template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); }

// Constants
const ld PI = 3.1415926535897932384626433832795L;
const ld EPS = 1e-11;
char TEMPORARY_CHAR;
// Types
typedef long long ll;
typedef unsigned long long u64;
typedef set < int > SI;
typedef vector < int > VI;
typedef vector < vector < int > > VVI;
typedef map < string, int > MSI;
typedef pair < int, int > PII;

const ll INF = 1e17;

const int N = 1 << 16;

inline void input(int &a)
{
    a = 0;
    while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-'))
    {}
    char neg = 0;
    if (TEMPORARY_CHAR == '-')
    {
        neg = 1;
        TEMPORARY_CHAR = getchar();
    }

    while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0')
    {
        a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0';
        TEMPORARY_CHAR = getchar();
    }

    if (neg)
        a = -a;
}
inline int nxt() {in(ret); return ret;}

#define x first
#define y second

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    in(n);
    in(a);in(b);
    int h[n];
    int com_s = 0;
    forn(i, n)
    {
        h[i] = nxt();
        com_s += h[i];
    }
    int can[2][n][com_s + 1];
    forn(i, n)
        forn(j, com_s + 1)
        {
            can[0][i][j] = -1;
            can[1][i][j] = -1;
        }
    can[0][0][h[0]] = 0;
    can[1][0][0] = 0;
    forn(i, n)
        if (i)
        {
            For(j, 0, com_s - h[i])
            {
                if (can[0][i - 1][j] != -1)
                {
                    int s = j;
                    int unlike = can[0][i - 1][j];
                    can[0][i][s + h[i]] = unlike;
                    can[1][i][s] = unlike + min(h[i], h[i - 1]);
                }
                if (can[1][i - 1][j] != -1)
                {
                    int s = j + h[i];
                    int unlike = can[1][i - 1][j] + min(h[i], h[i - 1]);
                    if (can[0][i][s] != -1)
                        unlike = min(unlike, can[0][i][s]);
                    can[0][i][s] = unlike;

                    s = j;
                    unlike = can[1][i - 1][j];
                    if (can[1][i][s] != -1)
                        unlike = min(unlike, can[1][i][s]);
                    can[1][i][s] = unlike;
                }
            }

        }
    int mi = 10000000;
    forn(j, com_s + 1)
    {
        int s = j;
        int unlike = can[0][n - 1][j];
        if (unlike != - 1 && s <= a && ((com_s - s) <= b) && unlike < mi)
            mi = unlike;
    }
    forn(j, com_s + 1)
    {
        int s = j;
        int unlike = can[1][n - 1][j];
        if (unlike != - 1 && s <= a && ((com_s - s) <= b) && unlike < mi)
            mi = unlike;
    }
    if (mi != 10000000)
        cout << mi << endl;
    else
        cout << "-1" << endl;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz size()
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define out(x) cout << (x);

typedef long double ld;
template <class _T> inline _T sqr(const _T& x) { return x * x; }
template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); }

// Constants
const ld PI = 3.1415926535897932384626433832795L;
const ld EPS = 1e-11;
char TEMPORARY_CHAR;
// Types
typedef long long ll;
typedef unsigned long long u64;
typedef set < int > SI;
typedef vector < int > VI;
typedef vector < vector < int > > VVI;
typedef map < string, int > MSI;
typedef pair < int, int > PII;

const ll INF = 1e17;

const int N = 1 << 16;

inline void input(int &a)
{
    a = 0;
    while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-'))
    {}
    char neg = 0;
    if (TEMPORARY_CHAR == '-')
    {
        neg = 1;
        TEMPORARY_CHAR = getchar();
    }

    while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0')
    {
        a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0';
        TEMPORARY_CHAR = getchar();
    }

    if (neg)
        a = -a;
}
inline int nxt() {in(ret); return ret;}

#define x first
#define y second

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    in(n);
    in(a);in(b);
    int h[n];
    int com_s = 0;
    forn(i, n)
    {
        h[i] = nxt();
        com_s += h[i];
    }
    int can[2][n][com_s + 1];
    forn(i, n)
        forn(j, com_s + 1)
        {
            can[0][i][j] = -1;
            can[1][i][j] = -1;
        }
    can[0][0][h[0]] = 0;
    can[1][0][0] = 0;
    forn(i, n)
        if (i)
        {
            forn(j, com_s + 1)
            {
                if (can[0][i - 1][j] != -1)
                {
                    int s = j;
                    int unlike = can[0][i - 1][j];
                    can[0][i][s + h[i]] = unlike;
                    can[1][i][s] = unlike + min(h[i], h[i - 1]);
                }

            }
            forn(j, com_s + 1)
            {
                if (can[1][i - 1][j] != -1)
                {
                    int s = j + h[i];
                    int unlike = can[1][i - 1][j] + min(h[i], h[i - 1]);
                    if (can[0][i][s] != -1)
                        unlike = min(unlike, can[0][i][s]);
                    can[0][i][s] = unlike;

                    s = j;
                    unlike = can[1][i - 1][j];
                    if (can[1][i][s] != -1)
                        unlike = min(unlike, can[1][i][s]);
                    can[1][i][s] = unlike;
                }
            }

        }
    int mi = 10000000;
    forn(j, com_s + 1)
    {
        int s = j;
        int unlike = can[0][n - 1][j];
        if (s <= a && ((com_s - s) <= b) && unlike < mi)
            mi = unlike;
    }
    forn(j, com_s + 1)
    {
        int s = j;
        int unlike = can[1][n - 1][j];
        if (s <= a && ((com_s - s) <= b) && unlike < mi)
            mi = unlike;
    }
    if (mi != 10000000)
        cout << mi << endl;
    else
        cout << "-1" << endl;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz size()
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define out(x) cout << (x);

typedef long double ld;
template <class _T> inline _T sqr(const _T& x) { return x * x; }
template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); }

// Constants
const ld PI = 3.1415926535897932384626433832795L;
const ld EPS = 1e-11;
char TEMPORARY_CHAR;
// Types
typedef long long ll;
typedef unsigned long long u64;
typedef set < int > SI;
typedef vector < int > VI;
typedef vector < vector < int > > VVI;
typedef map < string, int > MSI;
typedef pair < int, int > PII;

const ll INF = 1e17;

const int N = 1 << 16;

inline void input(int &a)
{
    a = 0;
    while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-'))
    {}
    char neg = 0;
    if (TEMPORARY_CHAR == '-')
    {
        neg = 1;
        TEMPORARY_CHAR = getchar();
    }

    while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0')
    {
        a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0';
        TEMPORARY_CHAR = getchar();
    }

    if (neg)
        a = -a;
}
inline int nxt() {in(ret); return ret;}

#define x first
#define y second

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    in(n);
    in(a);in(b);
    int h[n];
    int com_s = 0;
    forn(i, n)
    {
        h[i] = nxt();
        com_s += h[i];
    }
    int can[2][n][com_s + 1];
    forn(i, n)
        forn(j, com_s + 1)
        {
            can[0][i][j] = -1;
            can[1][i][j] = -1;
        }
    can[0][0][h[0]] = 0;
    can[1][0][0] = 0;
    forn(i, n)
        if (i)
        {
            forn(j, com_s + 1)
            {
                if (can[0][i — 1][j] != -1)
                {
                    int s = j;
                    int unlike = can[0][i — 1][j];
                    can[0][i][s + h[i]] = unlike;
                    can[1][i][s] = unlike + min(h[i], h[i — 1]);
                }

            }
            forn(j, com_s + 1)
            {
                if (can[1][i - 1][j] != -1)
                {
                    int s = j + h[i];
                    int unlike = can[1][i - 1][j] + min(h[i], h[i - 1]);
                    if (can[0][i][s] != -1)
                        unlike = min(unlike, can[0][i][s]);
                    can[0][i][s] = unlike;

                    s = j;
                    unlike = can[1][i - 1][j];
                    if (can[1][i][s] != -1)
                        unlike = min(unlike, can[1][i][s]);
                    can[1][i][s] = unlike;
                }
            }

        }
    int mi = 10000000;
    forn(j, com_s + 1)
    {
        int s = j;
        int unlike = can[0][n - 1][j];
        if (s <= a && ((com_s - s) <= b) && unlike < mi)
            mi = unlike;
    }
    forn(j, com_s + 1)
    {
        int s = j;
        int unlike = can[1][n - 1][j];
        if (s <= a && ((com_s - s) <= b) && unlike < mi)
            mi = unlike;
    }
    if (mi != 10000000)
        cout << mi << endl;
    else
        cout << "-1" << endl;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz size()
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define out(x) cout << (x);

typedef long double ld;
template <class _T> inline _T sqr(const _T& x) { return x * x; }
template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); }

// Constants
const ld PI = 3.1415926535897932384626433832795L;
const ld EPS = 1e-11;
char TEMPORARY_CHAR;
// Types
typedef long long ll;
typedef unsigned long long u64;
typedef set < int > SI;
typedef vector < int > VI;
typedef vector < vector < int > > VVI;
typedef map < string, int > MSI;
typedef pair < int, int > PII;

const ll INF = 1e17;

const int N = 1 << 16;

inline void input(int &a)
{
    a = 0;
    while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-'))
    {}
    char neg = 0;
    if (TEMPORARY_CHAR == '-')
    {
        neg = 1;
        TEMPORARY_CHAR = getchar();
    }

    while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0')
    {
        a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0';
        TEMPORARY_CHAR = getchar();
    }

    if (neg)
        a = -a;
}
inline int nxt() {in(ret); return ret;}

#define x first
#define y second

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    in(n);
    in(a);in(b);
    int h[n];
    int com_s = 0;
    forn(i, n)
    {
        h[i] = nxt();
        com_s += h[i];
    }
    map <int, int> can[2][n];
    can[0][0][h[0]] = 0;
    can[1][0][0] = 0;
    forn(i, n)
        if (i)
        {
            fori(it, can[0][i - 1])
            {
                int s = it -> x;
                int unlike = it -> y;
                can[0][i][s + h[i]] = unlike;
                can[1][i][s] = unlike + min(h[i], h[i - 1]);

            }
            fori(it, can[1][i - 1])
            {
                int s = it -> x + h[i];
                int unlike = it -> y + min(h[i], h[i - 1]);
                if (can[0][i].count(s))
                    unlike = min(unlike, can[0][i][s]);
                can[0][i][s] = unlike;

                s = it -> x;
                unlike = it -> y;
                if (can[1][i].count(s))
                    unlike = min(unlike, can[1][i][s]);
                can[1][i][s] = unlike;
            }

        }
    int mi = 10000000;
    fori(it, can[0][n - 1])
    {
        int s = it -> x;
        int unlike = it -> y;
        if (s <= a && ((com_s - s) <= b) && unlike < mi)
            mi = unlike;
    }
    fori(it, can[1][n - 1])
    {
        int s = it -> x;
        int unlike = it -> y;
        if (s <= a && ((com_s - s) <= b) && unlike < mi)
            mi = unlike;
    }
    if (mi != 10000000)
    {
        cout << mi << endl;
    }
    else
    {
        cout << "-1" << endl;
    }

    return 0;
}


/**
 * ID: ping128
 * LANG: C++
 */

#include <stdio.h>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <math.h>
#include <algorithm>
#include <map>
#include <string.h>

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;
typedef pair<PII, int>PII2;

int n;

LL dp[2][205][40005];   // a
LL h[205];
int a, b;
LL s[205];

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> n;
    cin >> a >> b;
    for(int i = 0; i < n; i++ )
    {
        cin >> h[i];
    }

    s[0] = h[0];
    for(int i = 1; i < n; i++ )
        s[i] = s[i - 1] + h[i];

    for(int i = 0; i < 205; i++ )
        for(int j = 0; j < 40005; j++ )
            dp[0][i][j] = dp[1][i][j] = 1000000000;

    if(a >= h[0]) dp[0][0][a - h[0]] = 0;
    if(b >= h[0]) dp[1][0][a] = 0;

    for(int i = 1; i < n; i++ )
    {
        for(int j = 0; j < 2; j++ )
        {
            for(int k = 0; k <= a; k++ )
            {
                if(j == 0)
                {
                    // same color
                    if(k + h[i] <= a)
                        dp[j][i][k] = min(dp[j][i][k], dp[0][i - 1][k + h[i]]);
                    // diff
                    if(k + h[i] <= a)
                        dp[j][i][k] = min(dp[j][i][k], dp[1][i - 1][k + h[i]] + min(h[i], h[i - 1]));
                }
                else
                {
                    if(s[i] - (a - k) <= b)
                        dp[j][i][k] = min(dp[j][i][k], dp[1][i - 1][k]);
                    if(s[i] - (a - k) <= b)
                        dp[j][i][k] = min(dp[j][i][k], dp[j ^ 1][i - 1][k] + min(h[i], h[i - 1]));
                }
            }
        }
    }

    LL minn = 1000000000;
    for(int i = 0; i < 2; i++ )
        for(int j = 0; j <= a; j++ )
            minn = min(minn, dp[i][n - 1][j]);
    if(minn == 1000000000)
    {
        cout << "-1" << endl;
    }
    else cout << minn << endl;

return 0;
}


#include <iostream>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <set>
#include <map>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define DB(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long LL;

const int MAXN = 209;
const int MAXA = 4 * 10009;

int n, a, b;
vector<int> h;
int dp[MAXN][MAXA][3];
int sumLen[MAXN];

int calcDP(int pos, int have, int prevColor)
{
  if (pos == n)
    return 0;

  if (dp[pos][have][prevColor] == -1)
  {
    int na = have;
    int nb = 0;
    if (pos > 0)
      nb = b - (sumLen[pos - 1] - (a - have));
    else
      nb = b;

    dp[pos][have][prevColor] = -2;

    if (na >= h[pos])
    {
      int nDP = calcDP(pos + 1, na - h[pos], 0);
      if (nDP != -2)
      {
        if (prevColor != 2 && prevColor != 0)
          nDP += min(h[pos], h[pos - 1]);
        if (dp[pos][have][prevColor] == -2 || dp[pos][have][prevColor] > nDP)
          dp[pos][have][prevColor] = nDP;
      }
    }
    if (nb >= h[pos])
    {
      int nDP = calcDP(pos + 1, na, 1);
      if (nDP != -2)
      {
        if (prevColor != 2 && prevColor != 1)
          nDP += min(h[pos], h[pos - 1]);
        if (dp[pos][have][prevColor] == -2 || dp[pos][have][prevColor] > nDP)
          dp[pos][have][prevColor] = nDP;
      }
    }
  }
  /*DB(pos);
  DB(have);
  DB(prevColor);
  DB(dp[pos][have][prevColor]);*/
  return dp[pos][have][prevColor];
}

int main()
{
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#ifdef _DEBUG
#endif
  scanf("%d", &n);
  scanf("%d%d", &a, &b);
  h.resize(n);
  REP(i, n)
  {
    scanf("%d", &h[i]);
    if (i)
      sumLen[i] = sumLen[i - 1];
    sumLen[i] += h[i];
  }

  memset(dp, -1, sizeof(dp));
  int res = calcDP(0, a, 2);
  if (res == -2)
  {
    printf("-1\n");
  }
  else
  {
    printf("%d\n", res);
  }

  return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define inf 0xfffffff
int h[210];
int dp[210][40010][2];
int sum[210];
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	int n;
	int a,b;
	scanf("%d %d %d",&n,&a,&b);
	h[0]=0;
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	sum[0]=0;
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+h[i];
	for(int i=0;i<210;i++)
		for(int j=0;j<40010;j++)
			for(int k=0;k<2;k++)
				dp[i][j][k]=inf;
	dp[0][0][0]=dp[0][0][1]=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<=sum[i];j++)
			for(int k=0;k<2;k++)
			{
				if(dp[i][j][k] == inf)
					continue;
				int now=h[i+1];
				if(j+now <= a)
				{
					if(k == 0)
						dp[i+1][j+now][0]=min(dp[i+1][j+now][0],dp[i][j][k]);
					if(k == 1)
						dp[i+1][j+now][0]=min(dp[i+1][j+now][0],dp[i][j][k]+min(h[i],h[i+1]));
				}
				if(sum[i+1]-j <= b)
				{
					if(k == 0)
						dp[i+1][j][1]=min(dp[i+1][j][1],dp[i][j][k]+min(h[i],h[i+1]));
					if(k == 1)
						dp[i+1][j][1]=min(dp[i+1][j][1],dp[i][j][k]);
				}
			}
	int ans=inf;
	for(int j=0;j<40010;j++)
		for(int k=0;k<2;k++)
			ans=min(ans,dp[n][j][k]);
	if(ans == inf)
		printf("-1\n");
	else
		printf("%d\n",ans);
	return 0;
}


// Warning! It's HadronWave code (c)
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979;
const int INF = 1<<27;

int A[202];
int DP[202][40001][2];

int main()
{
    //freopen("tables.in","r",stdin);
    //freopen("tables.out","w",stdout);
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);

    for(int i=0;i<=201;++i){
        for(int j=0;j<=40000;++j){
            DP[i][j][0] = DP[i][j][1] = INF;
        }
    }
    DP[0][0][0] = DP[0][0][1] = 0;
    int n,a,b,sum=0;
    scanf("%d%d%d",&n,&a,&b);

    for(int i=1;i<=n;++i){
        scanf("%d",&A[i]);

        for(int j=a;j>=0;--j){
            int other = sum - j;
            if(j+A[i]<=a){
                DP[i][j+A[i]][0] = min(DP[i-1][j][0],DP[i][j+A[i]][0]);
                DP[i][j+A[i]][0] = min(DP[i-1][j][1]+min(A[i-1],A[i]),DP[i][j+A[i]][0]);
            }
            if(other>=0 && other+A[i]<=b) {
                DP[i][j][1] = min(DP[i-1][j][1],DP[i][j][1]);
                DP[i][j][1] = min(DP[i-1][j][0] + min(A[i-1],A[i]),DP[i][j][1]);
            }

        }
        sum += A[i];
    }
    int Min = INF;
    for(int j=a;j>=0;--j) Min = min(Min,min(DP[n][j][1],DP[n][j][0]));
    printf("%d",Min>=INF?-1:Min);
    return 0;
}


import java.io.BufferedReader;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    private static final int INF = Integer.MAX_VALUE / 2;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int[] h = Utils.readIntArray(in, n);
        int[] sum = new int[n];
        for (int i = 0; i < n; ++i) {
            if (i == 0) {
                sum[i] = h[i];
            } else {
                sum[i] = h[i] + sum[i - 1];
            }
        }
        int[][] dp = new int[a + 1][2];
        int[][] next = new int[a + 1][2];
        ArrayUtils.fill(dp, INF);
        ArrayUtils.fill(next, INF);
        if (h[0] <= a) {
            dp[h[0]][0] = 0;
        }
        if (h[0] <= b) {
            dp[0][1] = 0;
        }
        for (int i = 1; i < n; ++i) {
            for (int amA = 0; amA <= a; ++amA) {
                for (int past = 0; past < 2; ++past) {
                    if (dp[amA][past] < INF) {
                        if (past == 0) {
                            if (h[i] + amA <= a) {
                                next[h[i] + amA][0] = Math.min(next[h[i] + amA][0], dp[amA][0]);
                            }
                            int amB = sum[i - 1] - amA;
                            if (h[i] + amB <= b) {
                                next[amA][1] = Math.min(next[amA][1], dp[amA][0] + Math.min(h[i - 1], h[i]));
                            }
                        } else {
                            if (h[i] + amA <= a) {
                                next[h[i] + amA][0] = Math.min(next[h[i] + amA][0], dp[amA][1] + Math.min(h[i - 1], h[i]));
                            }
                            int amB = sum[i - 1] - amA;
                            if (h[i] + amB <= b) {
                                next[amA][1] = Math.min(next[amA][1], dp[amA][1]);
                            }
                        }
                    }
                }
            }
            for (int amA = 0; amA <= a; ++amA) {
                for (int past = 0; past < 2; ++past) {
                    dp[amA][past] = next[amA][past];
                    next[amA][past] = INF;
                }
            }
        }
        int best = INF;
        for (int amA = 0; amA <= a; ++amA) {
            for (int past = 0; past < 2; ++past) {
                best = Math.min(dp[amA][past], best);
            }
        }
        if (best == INF) {
            best = -1;
        }
        out.println(best);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}

class Utils {
    public static int[] readIntArray(InputReader in, int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        return a;
    }

}

class ArrayUtils {

    public static void fill(int[][] f, int value) {
        for (int i = 0; i < f.length; ++i) {
            Arrays.fill(f[i], value);
        }
    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

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

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	private void run() throws IOException {
		if (new File("input.txt").exists())
			in = new BufferedReader(new FileReader("input.txt"));
		else
			in = new BufferedReader(new InputStreamReader(System.in));
		if (new File("output.txt").exists())
			out = new PrintWriter("output.txt");
		else
			out = new PrintWriter(System.out);

		solve();

		in.close();
		out.close();
	}

	final int MAX_N = 201;
	final int MAX_COLOR = 4 * 10 * 1000 + 10;
	final int inf = Integer.MAX_VALUE / 2 - 1;

	int n, a, b;
	int h[] = new int[MAX_N];
	int sh[] = new int[MAX_N];

	int d[][][] = new int[2][MAX_N][MAX_COLOR];

	void solve() throws IOException {
		n = nextInt();
		a = nextInt();
		b = nextInt();
		for (int i = 0; i < n; i++)
			h[i] = nextInt();
		sh[0] = h[0];
		for (int i = 1; i < n; i++)
			sh[i] = sh[i - 1] + h[i];

		for (int i = 0; i < 2; i++)
			for (int j = 0; j < n; j++)
				fill(d[i][j], inf);

		if (h[0] <= a)
			d[1][0][h[0]] = 0;
		if (h[0] <= b)
			d[0][0][0] = 0;
		for (int i = 0; i < n - 1; i++)
			for (int useA = 0, useB = sh[i]; useA <= a && useB >= 0; useA++, useB--)
				if (useB <= b) {

					if (d[0][i][useA] != inf) {
						if (useA + h[i + 1] <= a)
							d[1][i + 1][useA + h[i + 1]] = min(d[1][i + 1][useA + h[i + 1]], d[0][i][useA] + min(h[i], h[i + 1]));
						if (useB + h[i + 1] <= b)
							d[0][i + 1][useA] = min(d[0][i + 1][useA], d[0][i][useA]);
					}

					if (d[1][i][useA] != inf) {
						if (useA + h[i + 1] <= a)
							d[1][i + 1][useA + h[i + 1]] = min(d[1][i + 1][useA + h[i + 1]], d[1][i][useA]);
						if (useB + h[i + 1] <= b)
							d[0][i + 1][useA] = min(d[0][i + 1][useA], d[1][i][useA] + min(h[i], h[i + 1]));
					}

				}

		int ans = inf;
		for (int useA = 0, useB = sh[n - 1]; useA <= a && useB >= 0; useA++, useB--)
			ans = min(ans, min(d[0][n - 1][useA], d[1][n - 1][useA]));
		if (ans == inf)
			ans = -1;

		out.println(ans);
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

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

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

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

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String str = in.readLine();
			if (str == null)
				return true;
			st = new StringTokenizer(str);
		}
		return false;
	}

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

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

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	private void run() throws IOException {
//		if (new File("input.txt").exists())
//			in = new BufferedReader(new FileReader("input.txt"));
//		else
//			in = new BufferedReader(new InputStreamReader(System.in));
//		if (new File("output.txt").exists())
//			out = new PrintWriter("output.txt");
//		else
//			out = new PrintWriter(System.out);

		in = new BufferedReader(new FileReader("input.txt"));
		out = new PrintWriter("output.txt");

		solve();

		in.close();
		out.close();
	}

	final int MAX_N = 201;
	final int MAX_COLOR = 4 * 10 * 1000 + 10;
	final int inf = Integer.MAX_VALUE / 2 - 1;

	int n, a, b;
	int h[] = new int[MAX_N];
	int sh[] = new int[MAX_N];

	int d[][][] = new int[2][MAX_N][MAX_COLOR];

	void solve() throws IOException {
		n = nextInt();
		a = nextInt();
		b = nextInt();
		for (int i = 0; i < n; i++)
			h[i] = nextInt();
		sh[0] = h[0];
		for (int i = 1; i < n; i++)
			sh[i] = sh[i - 1] + h[i];

		for (int i = 0; i < 2; i++)
			for (int j = 0; j < n; j++)
				fill(d[i][j], inf);

		if (h[0] <= a)
			d[1][0][h[0]] = 0;
		if (h[0] <= b)
			d[0][0][0] = 0;
		for (int i = 0; i < n - 1; i++)
			for (int useA = 0, useB = sh[i]; useA <= a && useB >= 0; useA++, useB--)
				if (useB <= b) {

					if (d[0][i][useA] != inf) {
						if (useA + h[i + 1] <= a)
							d[1][i + 1][useA + h[i + 1]] = min(d[1][i + 1][useA + h[i + 1]], d[0][i][useA] + min(h[i], h[i + 1]));
						if (useB + h[i + 1] <= b)
							d[0][i + 1][useA] = min(d[0][i + 1][useA], d[0][i][useA]);
					}

					if (d[1][i][useA] != inf) {
						if (useA + h[i + 1] <= a)
							d[1][i + 1][useA + h[i + 1]] = min(d[1][i + 1][useA + h[i + 1]], d[1][i][useA]);
						if (useB + h[i + 1] <= b)
							d[0][i + 1][useA] = min(d[0][i + 1][useA], d[1][i][useA] + min(h[i], h[i + 1]));
					}

				}

		int ans = inf;
		for (int useA = 0, useB = sh[n - 1]; useA <= a && useB >= 0; useA++, useB--)
			ans = min(ans, min(d[0][n - 1][useA], d[1][n - 1][useA]));
		if (ans == inf)
			ans = -1;

		out.println(ans);
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

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

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

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

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String str = in.readLine();
			if (str == null)
				return true;
			st = new StringTokenizer(str);
		}
		return false;
	}

}


import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.StringTokenizer;

public class fences {

  static int INF = 2000000000;
  public static void main(String[] args) throws Exception {
    BufferedReader in = new BufferedReader(new FileReader("input.txt"));
    BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
    int n = Integer.parseInt(in.readLine());
    StringTokenizer st = new StringTokenizer(in.readLine());
    int r = Integer.parseInt(st.nextToken());
    int g = Integer.parseInt(st.nextToken());
    int[] h = new int[n + 1];
    int[] sum = new int[n + 1];
    for (int i = 0; i < n + 1; i++) sum[i] = 0;
    st = new StringTokenizer(in.readLine());
    h[0] = 0;
    sum[0] = 0;
    for (int i = 0; i < n; i++) {
      h[i + 1] = Integer.parseInt(st.nextToken());
      sum[i + 1] += (sum[i] + h[i]);
    }
    int[][][] dp = new int[n + 1][r + 1][2];
    for (int k = 0; k < n + 1; k++) {
      for (int i = 0; i < r + 1; i++) {
        dp[k][i][0] = INF;
        dp[k][i][1] = INF;
      }
    }
    dp[0][0][0] = 0;
    for (int i = 1; i < dp.length; i++) {
      for (int k = 0; k < dp[i].length; k++) {
        if (sum[i] - k > g) continue;
        dp[i][k][0] = Math.min(dp[i - 1][k][0], dp[i - 1][k][1] + Math.min(h[i], h[i - 1]));
        if (k >= h[i]) dp[i][k][1] = Math.min(dp[i - 1][k][1], dp[i - 1][k - h[i]][0] + Math.min(h[i], h[i - 1]));
      }
    }
    int ans = INF;
    for (int i = 0; i < r + 1; i++) {
      ans = Math.min(ans, Math.min(dp[n][i][0], dp[n][i][1]));
    }
    if (ans == INF) {
      out.write("-1\n");
    } else {
      out.write("" + ans + "\n");
    }
    out.close();
    System.exit(0);
  }
}


import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.StringTokenizer;

public class fences {

  static int INF = 2000000000;
  public static void main(String[] args) throws Exception {
    BufferedReader in = new BufferedReader(new FileReader("input.txt"));
    BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
    int n = Integer.parseInt(in.readLine());
    StringTokenizer st = new StringTokenizer(in.readLine());
    int r = Integer.parseInt(st.nextToken());
    int g = Integer.parseInt(st.nextToken());
    int[] h = new int[n + 1];
    int[] sum = new int[n + 1];
    for (int i = 0; i < n + 1; i++) sum[i] = 0;
    st = new StringTokenizer(in.readLine());
    h[0] = 0;
    sum[0] = 0;
    for (int i = 0; i < n; i++) {
      h[i + 1] = Integer.parseInt(st.nextToken());
      sum[i + 1] += (sum[i] + h[i + 1]);
    }
    int[][][] dp = new int[n + 1][r + 1][2];
    for (int k = 0; k < n + 1; k++) {
      for (int i = 0; i < r + 1; i++) {
        dp[k][i][0] = INF;
        dp[k][i][1] = INF;
      }
    }
    dp[0][0][0] = 0;
    for (int i = 1; i < dp.length; i++) {
      for (int k = 0; k < dp[i].length; k++) {
        if (sum[i] - k > g) continue;
        dp[i][k][0] = Math.min(dp[i - 1][k][0], dp[i - 1][k][1] + Math.min(h[i], h[i - 1]));
        if (k >= h[i]) dp[i][k][1] = Math.min(dp[i - 1][k - h[i]][1], dp[i - 1][k - h[i]][0] + Math.min(h[i], h[i - 1]));
      }
    }
    int ans = INF;
    for (int i = 0; i < r + 1; i++) {
      ans = Math.min(ans, Math.min(dp[n][i][0], dp[n][i][1]));
    }
    if (ans == INF) {
      out.write("-1\n");
    } else {
      out.write("" + ans + "\n");
    }
    out.close();
    System.exit(0);
  }
}


import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.StringTokenizer;

public class fences {

  static int INF = 2000000000;
  public static void main(String[] args) throws Exception {
    BufferedReader in = new BufferedReader(new FileReader("input.txt"));
    BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
    int n = Integer.parseInt(in.readLine());
    StringTokenizer st = new StringTokenizer(in.readLine());
    int r = Integer.parseInt(st.nextToken());
    int g = Integer.parseInt(st.nextToken());
    int[] h = new int[n + 1];
    st = new StringTokenizer(in.readLine());
    h[0] = 0;
    for (int i = 0; i < n; i++) {
      h[i + 1] = Integer.parseInt(st.nextToken());
    }
    int[][][] dp = new int[n + 1][r + 1][2];
    for (int k = 0; k < n + 1; k++) {
      for (int i = 0; i < r + 1; i++) {
        dp[k][i][0] = INF;
        dp[k][i][1] = INF;
      }
    }
    dp[0][0][0] = 0;
    int sum = 0;
    for (int i = 1; i < dp.length; i++) {
      sum += h[i];
      for (int k = 0; k < dp[i].length; k++) {
        if (sum - k > g) continue;
        dp[i][k][0] = Math.min(dp[i - 1][k][0], dp[i - 1][k][1] + Math.min(h[i], h[i - 1]));
        if (k >= h[i]) dp[i][k][1] = Math.min(dp[i - 1][k - h[i]][1], dp[i - 1][k - h[i]][0] + Math.min(h[i], h[i - 1]));
      }
    }
    int ans = INF;
    for (int i = 0; i < r + 1; i++) {
      ans = Math.min(ans, Math.min(dp[n][i][0], dp[n][i][1]));
    }
    if (ans == INF) {
      out.write("-1\n");
    } else {
      out.write("" + ans + "\n");
    }
    out.close();
    System.exit(0);
  }
}


import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.StringTokenizer;

public class fences {

  static int INF = 2000000000;
  public static void main(String[] args) throws Exception {
    BufferedReader in = new BufferedReader(new FileReader("input.txt"));
    BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
    int n = Integer.parseInt(in.readLine());
    StringTokenizer st = new StringTokenizer(in.readLine());
    int r = Integer.parseInt(st.nextToken());
    int g = Integer.parseInt(st.nextToken());
    int[] h = new int[n + 1];
    st = new StringTokenizer(in.readLine());
    h[0] = 0;
    for (int i = 0; i < n; i++) {
      h[i + 1] = Integer.parseInt(st.nextToken());
    }
    int[][] dp1 = new int[r + 1][2];
    int[][] dp2 = new int[r + 1][2];
    for (int i = 0; i < r + 1; i++) {
      dp1[i][0] = INF;
      dp1[i][1] = INF;
      dp2[i][0] = INF;
      dp2[i][1] = INF;
    }
    dp1[0][0] = 0;
    dp1[0][1] = 0;
    int sum = 0;
    for (int i = 1; i < n + 1; i++) {
      sum += h[i];
      for (int k = 0; k < r + 1; k++) {
        if (sum - k > g) continue;
        dp2[k][0] = Math.min(dp1[k][0], dp1[k][1] + Math.min(h[i], h[i - 1]));
        if (k >= h[i]) dp2[k][1] = Math.min(dp1[k - h[i]][1], dp1[k - h[i]][0] + Math.min(h[i], h[i - 1]));
      }
      for (int k = 0; k < r + 1; k++) {
        dp1[k][0] = dp2[k][0];
        dp1[k][1] = dp2[k][1];
      }
      for (int k = 0; k < r + 1; k++) {
        dp2[k][0] = INF;
        dp2[k][1] = INF;
      }
    }
    int ans = INF;
    for (int i = 0; i < r + 1; i++) {
      ans = Math.min(ans, Math.min(dp1[i][0], dp1[i][1]));
    }
    if (ans == INF) {
      out.write("-1\n");
    } else {
      out.write("" + ans + "\n");
    }
    out.close();
    System.exit(0);
  }
}


import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.StringTokenizer;

public class fences {

  static int INF = 2000000000;
  public static void main(String[] args) throws Exception {
    BufferedReader in = new BufferedReader(new FileReader("input.txt"));
    BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
    int n = Integer.parseInt(in.readLine());
    StringTokenizer st = new StringTokenizer(in.readLine());
    int r = Integer.parseInt(st.nextToken());
    int g = Integer.parseInt(st.nextToken());
    int[] h = new int[n + 1];
    int[] sum = new int[n + 1];
    for (int i = 0; i < n + 1; i++) sum[i] = 0;
    st = new StringTokenizer(in.readLine());
    h[0] = 0;
    sum[0] = 0;
    for (int i = 0; i < n; i++) {
      h[i + 1] = Integer.parseInt(st.nextToken());
      sum[i + 1] += (sum[i] + h[i]);
    }
    int[][][] dp = new int[n + 1][r + 1][2];
    for (int k = 0; k < n + 1; k++) {
      for (int i = 0; i < r + 1; i++) {
        dp[k][i][0] = INF;
        dp[k][i][1] = INF;
      }
    }
    dp[0][0][0] = 0;
    dp[0][0][1] = 0;
    for (int i = 1; i < dp.length; i++) {
      for (int k = 0; k < dp[i].length; k++) {
        if (sum[i] - k > g) continue;
        dp[i][k][0] = Math.min(dp[i - 1][k][0], dp[i - 1][k][1] + Math.min(h[i], h[i - 1]));
        if (k >= h[i]) dp[i][k][1] = Math.min(dp[i - 1][k][1], dp[i - 1][k - h[i]][0] + Math.min(h[i], h[i - 1]));
      }
    }
    int ans = INF;
    for (int i = 0; i < r + 1; i++) {
      ans = Math.min(ans, Math.min(dp[n][i][0], dp[n][i][1]));
    }
    if (ans == INF) {
      out.write("-1\n");
    } else {
      out.write("" + ans + "\n");
    }
    out.close();
    System.exit(0);
  }
}


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class B {
	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException	{
		br = new BufferedReader(new FileReader("input.txt"));
		pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
		int n = readInt();
		int a = readInt();
		int b = readInt();
		int[] list = new int[n];
		for(int i = 0; i < n; i++)	{
			list[i] = readInt();
		}
		PriorityQueue<State> q = new PriorityQueue<State>();
		int ret = Integer.MAX_VALUE;
		if(a >= list[0])	{
			q.add(new State(1, list[0], 0, 0, true));
		}
		if(b >= list[0])	{
			q.add(new State(1, 0, list[0], 0, false));
		}
		Set<State> seen = new HashSet<State>();
		while(!q.isEmpty())	{
			State curr = q.poll();
			if(curr.index == n)	{
				ret = curr.dist;
				break;
			}
			if(!seen.add(curr))
				continue;
			if(curr.a + list[curr.index] <= a)	{
				q.add(new State(curr.index+1, curr.a + list[curr.index], curr.b, curr.lastA ? curr.dist : curr.dist + Math.min(list[curr.index], list[curr.index-1]), true));
			}
			if(curr.b + list[curr.index] <= b)	{
				q.add(new State(curr.index+1, curr.a, curr.b + list[curr.index], !curr.lastA ? curr.dist : curr.dist + Math.min(list[curr.index], list[curr.index-1]), false));
			}
		}
		if(ret == Integer.MAX_VALUE)
			ret = -1;
		pw.println(ret);
		pw.close();
	}

	static class State implements Comparable<State> {
		public int index,a,b,dist;
		public boolean lastA;
		public State(int x, int w, int e, int r, boolean t)	{
			index=x;
			a=w;
			b=e;
			dist=r;
			lastA = t;
		}
		public int hashCode()	{
			int ans = index;
			ans *= 3137;
			ans += a;
			ans *= 3137;
			ans += b;
			if(lastA)
				ans++;
			return ans;
		}
		public boolean equals(Object o)	{
			State s = (State)o;
			return index == s.index && a == s.a && b == s.b && lastA == s.lastA;
		}
		public int compareTo(State out)	{
			return dist - out.dist;
		}
	}

	public static long readLong() throws IOException	{
		return Long.parseLong(nextToken());
	}
	public static double readDouble() throws IOException	{
		return Double.parseDouble(nextToken());
	}
	public static int readInt() throws IOException	{
		return Integer.parseInt(nextToken());
	}
	public static short readShort() throws IOException	{
		return Short.parseShort(nextToken());
	}
	public static String nextToken() throws IOException	{
		while(st == null || !st.hasMoreTokens())	{
			if(!br.ready())	{
				pw.close();
				System.exit(0);
			}
			st = new StringTokenizer(br.readLine().trim());
		}
		return st.nextToken();
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class F implements Runnable{

    static StringTokenizer st;
    static BufferedReader in;
    static PrintWriter pw;
    void solve() throws IOException{
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[]h = new int[n+1];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            h[i] = sc.nextInt();
            sum += h[i];
        }
        if (a >= sum || b >= sum) {
            pw.println(0);
            pw.close();
            return;
        }
        int INF = (int) 1e9;
        int[][][]dp = new int[2][n+1][a+1];
        for (int i = 0; i <= 1; i++) {
            for (int j = 0; j <= n; j++) {
                Arrays.fill(dp[i][j], INF);
            }
        }
        for (int i = 0; i <= n; i++) {
            dp[0][i][0] = 0;
        }
        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= n; j++) {
                dp[0][j][i] = Math.min(dp[0][j-1][i], dp[1][j-1][i]+Math.min(h[j], h[j-1]));
                if (h[j] <= i) {
                    dp[1][j][i] = Math.min(dp[1][j-1][i-h[j]], dp[0][j-1][i-h[j]]+Math.min(h[j], h[j-1]));
                }
            }
        }
        int min = INF;
        for (int i = 0; i <= a; i++) {
            if (b >= sum-i) {
                min = Math.min(min, Math.min(dp[0][n][i], dp[1][n][i]));
            }
        }
        if (min==INF)
            pw.println(-1);
        else
            pw.println(min);
        pw.close();
    }

    static Throwable uncaught;
    static FastScanner sc;
    @Override
    public void run() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            pw = new PrintWriter(new FileWriter("output.txt"));
            sc = new FastScanner(in);
            solve();
        } catch (Throwable t) {
            F.uncaught = t;
        } finally {
            pw.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(null, new F(), "", 128 * 1024 * 1024);
        t.start();
        t.join();
        if (uncaught != null) {
            throw uncaught;
        }
    }
}
class FastScanner {

    BufferedReader reader;
    StringTokenizer strTok;

    public FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public String nextToken() throws IOException {
        while (strTok == null || !strTok.hasMoreTokens()) {
            strTok = new StringTokenizer(reader.readLine());
        }
        return strTok.nextToken();
    }

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

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

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

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class F {

    static StringTokenizer st;
    static BufferedReader in;
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new FileReader("input.txt"));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        int n = nextInt();
        int a = nextInt();
        int b = nextInt();
        int[]h = new int[n+1];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            h[i] = nextInt();
            sum += h[i];
        }
        if (a >= sum || b >= sum) {
            pw.println(0);
            pw.close();
            return;
        }
        int INF = (int) 1e9;
        int[][][]dp = new int[a+1][n+1][2];
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= n; j++) {
                dp[i][j][0] = dp[i][j][1] = INF;
            }
        }
        for (int i = 0; i <= n; i++) {
            dp[0][i][0] = 0;
        }
        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= n; j++) {
                dp[i][j][0] = Math.min(dp[i][j-1][0], dp[i][j-1][1]+Math.min(h[j], h[j-1]));
                if (h[j] <= i) {
                    dp[i][j][1] = Math.min(dp[i-h[j]][j-1][1], dp[i-h[j]][j-1][0]+Math.min(h[j], h[j-1]));
                }
            }
        }
        int min = INF;
        for (int i = 0; i <= a; i++) {
            if (b >= sum-i) {
                min = Math.min(min, Math.min(dp[i][n][0], dp[i][n][1]));
            }
        }
        if (min==INF)
            pw.println(-1);
        else
            pw.println(min);
        pw.close();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class F {

    static StringTokenizer st;
    static BufferedReader in;
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new FileReader("input.txt"));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        int n = nextInt();
        int a = nextInt();
        int b = nextInt();
        int[]h = new int[n+1];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            h[i] = nextInt();
            sum += h[i];
        }
        if (a >= sum || b >= sum) {
            pw.println(0);
            pw.close();
            return;
        }
        int INF = (int) 1e9;
        int[][][]dp = new int[2][n+1][a+1];
        for (int i = 0; i <= 1; i++) {
            for (int j = 0; j <= n; j++) {
                Arrays.fill(dp[i][j], INF);
            }
        }
        for (int i = 0; i <= n; i++) {
            dp[0][i][0] = 0;
        }
        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= n; j++) {
                dp[0][j][i] = Math.min(dp[0][j-1][i], dp[1][j-1][i]+Math.min(h[j], h[j-1]));
                if (h[j] <= i) {
                    dp[1][j][i] = Math.min(dp[1][j-1][i-h[j]], dp[0][j-1][i-h[j]]+Math.min(h[j], h[j-1]));
                }
            }
        }
        int min = INF;
        for (int i = 0; i <= a; i++) {
            if (b >= sum-i) {
                min = Math.min(min, Math.min(dp[0][n][i], dp[1][n][i]));
            }
        }
        if (min==INF)
            pw.println(-1);
        else
            pw.println(min);
        pw.close();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class F implements Runnable{

    static StringTokenizer st;
    static BufferedReader in;
    static PrintWriter pw;
    public static void solve() throws IOException{
        in = new BufferedReader(new FileReader("input.txt"));
        pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        int n = nextInt();
        int a = nextInt();
        int b = nextInt();
        int[]h = new int[n+1];
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            h[i] = nextInt();
            sum += h[i];
        }
        if (a >= sum || b >= sum) {
            pw.println(0);
            pw.close();
            return;
        }
        int INF = (int) 1e9;
        int[][][]dp = new int[a+1][n+1][2];
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= n; j++) {
                dp[i][j][0] = dp[i][j][1] = INF;
            }
        }
        for (int i = 0; i <= n; i++) {
            dp[0][i][0] = 0;
        }
        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= n; j++) {
                dp[i][j][0] = Math.min(dp[i][j-1][0], dp[i][j-1][1]+Math.min(h[j], h[j-1]));
                if (h[j] <= i) {
                    dp[i][j][1] = Math.min(dp[i-h[j]][j-1][1], dp[i-h[j]][j-1][0]+Math.min(h[j], h[j-1]));
                }
            }
        }
        int min = INF;
        for (int i = 0; i <= a; i++) {
            if (b >= sum-i) {
                min = Math.min(min, Math.min(dp[i][n][0], dp[i][n][1]));
            }
        }
        if (min==INF)
            pw.println(-1);
        else
            pw.println(min);
        pw.close();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    static Throwable uncaught;

    @Override
    public void run() {
        try {
            //in = new BufferedReader(new InputStreamReader(System.in));
            //out = new PrintWriter(System.out);
            in = new BufferedReader(new FileReader("input.txt"));
            pw = new PrintWriter(new FileWriter("output.txt"));
            solve();
        } catch (Throwable t) {
            F.uncaught = t;
        } finally {
            pw.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread t = new Thread(null, new F(), "", 128 * 1024 * 1024);
        t.start();
        t.join();
        if (uncaught != null) {
            throw uncaught;
        }
    }
}