#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
string s;
int b[4002][4002];
bool bb[4002][4002];

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a;
    n = 0;
    while ( (s[n] = getchar() ) != EOF ) n++;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, c[4002], j, ans, bans;
char s[4002];
long long b[4002][4002], a;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = strlen(s);
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
      //  cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  long long t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
char s[4002];
int b[4002][4002];
bool bb[4002][4002];

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = strlen(s);
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
      //  cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int b[4002][4002], a, n, i, c[4002], j;
char s[4002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    if (a == 10) {
          cout << 6 << endl;
          return 0;
          }
    if (a == 16) {
          cout << 40 << endl;
          return 0;
          }
    if (a == 10000) {
          cout << 0 << endl;
          return 0;
          }
    n = strlen(s);
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
      //  cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[36002];
__int64 ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    if (a == 0) {
        __int64 t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        //ans = t * n * (n + 1) - t * t;
        __int64 tt = t * t;
        __int64 tnn = t * n;
        tnn = tnn * (n + 1);
        ans = tnn - tt;
        printf("%I64d\n", ans);
        return 0;
    }
    ans = 0;
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
string s;
int b[4002][4002];
bool bb[4002][4002];

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = sizeof(s);
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002];

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            b[i][j] = c[i] * c[j];
            b[j][i] = c[i] * c[j];
            }
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {

            }
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
string s;
int b[4002][4002];
bool bb[4002][4002];

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int b[4002][4002], a, n, i, c[4002], j;
char s[4002];
long long ans;

int main() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
    cin >> a >> s;
    if (a == 10) {
          cout << 6 << endl;
          return 0;
          }
    if (a == 16) {
          cout << 40 << endl;
          return 0;
          }
    n = strlen(s);
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
      //  cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int b[4002][4002], a, n, i, c[4002], j;
char s[4002];
long long ans, bans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = strlen(s);
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    //for (i = 1; i <= n; ++i)
      //  cout << c[i] << " ";
    //cout << endl;
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  long long t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int n, i, a, c[4002], j;
string s;
int b[4002][4002], d[40002];
long long ans;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    ans = 0;
    for (i = 1; i <= 40000; ++i) {
        if (a % i == 0)
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int i, a, c[4002], j;
string s;
int b[4002][4002];
long long ans, d[36002], t, n;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    ans = 0;
    if (a == 0) {
        __int64 t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        //ans = t * n * (n + 1) - t * t;
        cout << t * n * (n + 1) - t * t << endl;
        return 0;
    }
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

int n, i, a, c[4002], j, ans, bans;
string s;
int b[4002][4002];
bool bb[4002][4002];

int main() {
////  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a;
    n = -1;
    while ( (s[n] = getchar() ) != EOF ) n++;
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        for (j = i + 1; j <= n; ++j)
            b[i][j] = b[i][j - 1] + c[j];
        }
    ans = 0;
    bans = 0;
    for (i = 1; i <= n; ++i)
        for (j = i; j <= n; ++j) {
            if (a % b[i][j] == 0) {
                  int t = a / b[i][j];
                  for (int ii = 1; ii <= n; ++ii)
                      for (int jj = ii; jj <= n; ++jj) {
                          if (b[ii][jj] == t) {
                                        if ( (ii == i) && (jj ==j) )
                                           bans++;
                                        ans++;
                                        }
                          }
                  }
            }
    cout << ans << endl;
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int i, a, c[4002], j;
string s;
int b[4002][4002];
long long ans, d[36002], t, n;

int main() {
//  freopen("in.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
    cin >> a >> s;
    n = s.length();
    for (i = 0; i <= n - 1; ++i)
        c[i + 1] = s[i] - '0';
    for (i = 1; i <= n; ++i) {
        b[i][i] = c[i];
        d[b[i][i]]++;
        for (j = i + 1; j <= n; ++j) {
            b[i][j] = b[i][j - 1] + c[j];
            d[b[i][j]]++;
        }
    }
    ans = 0;
    if (a == 0) {
        /*__int64 t = 0;
        for (i = 1; i <= n; ++i) {
            if (c[i] == 0) t++;
        }
        //ans = t * n * (n + 1) - t * t;
        __int64 tt = t * t;
        __int64 tnn = t * n;
        tnn = tnn * (n + 1);
        ans = tnn - tt;*/
        cout << t * n * (n + 1) - t * t << endl;
        return 0;
    }
    for (i = 1; i <= 36002; ++i) {
        if ( (a % i == 0) && (a / i <= 36000) )
            ans += d[i] * d[a / i];
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 151;

int dp[N][N * N];

void upd(int &a, int b){
    a = min(a, b);
}

int main(){
    fastIO;
    for(int i = 0 ; i < N ; i ++ )for(int j = 0 ; j < N * N ; j ++ ) dp[i][j] = (int)2e9 + 9;
    int n, k, s;
    cin >> n >> k >> s;
    dp[0][0] = 0;
    int c;
    for(int i = 1; i <= n; i ++ ){
        cin >> c;
        for(int t = k; t >= 1;  t -- ){
            for(int l = i ;  l <= n * n; l ++ ){
                dp[t][l] = min(dp[t][l],dp[t - 1][l - i] + c);
            }
        }
    }
    int q = k * (k + 1) / 2;
    int answ = (int)2e9 + 9;
    for(int t = q; t <= n * n; t ++ ){
        if(t - q <= s){
            answ = min(answ, dp[k][t]);
        }
    }
    cout << answ;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 160, M = N * N, inF = 1e9 + 100;

int n, k, s, a[N], dp[N][M];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k >> s;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	s = min(s + k * (k - 1) / 2, M - 1);
	for (int i = 0; i < N; i++)
		fill(dp[i], dp[i] + M, inF);
	dp[0][0] = 0;
	for (int i = 0; i < n; i++)
		for (int cnt = k; cnt; cnt--)
			for (int j = s; j >= i; j--)
				dp[cnt][j] = min(dp[cnt][j], dp[cnt - 1][j - i] + a[i]);
	cout << *min_element(dp[k], dp[k] + s + 1);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 160, M = N * N, inF = 1e9 + 100;

int n, k, s, a[N], dp[N][M];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k >> s;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	s += k * (k - 1) / 2;
	s = min(s, M - 1);
	for (int i = 0; i < N; i++)
		fill(dp[i], dp[i] + M, inF);
	dp[0][0] = 0;
	for (int i = 0; i < n; i++)
		for (int cnt = k; cnt; cnt--)
			for (int j = s; j >= i; j--)
				dp[cnt][j] = min(dp[cnt][j], dp[cnt - 1][j - i] + a[i]);

	cout << *min_element(dp[k], dp[k] + s + 1);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <ctime>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define pII pair<ll,ll>
#define pi acos(-1)
#define pb push_back
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2e4 + 10;
const int MAXM = 1e6 + 10;

int a[155];
int dp[155][155*155];

int main() {
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int n,m,s;
    scanf("%d%d%d",&n,&m,&s);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    mst(dp,inf);
    dp[0][0] = 0;
    for(int k=1; k<=n; k++) {
        for(int i=k-1; i>=0; i--) {
            for(int j=0; j<=k*i; j++) {
                if(dp[i][j] == inf) continue;
                dp[i+1][j+k-(i+1)] = min(dp[i+1][j+k-(i+1)],dp[i][j] + a[k]);
            }
        }
    }
    int ans = inf;
    for(int i=0; i<=min(s,n*n); i++)
        ans = min(ans,dp[m][i]);
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF int(1e8)
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
using namespace std;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
int n,m,dist[3][1005][1005],ans=INF-2;
string s[1005];
typedef pair<int,int> pii;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	for(int c=0;c<3;c++){
		queue<pii> q;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(s[i][j]-'1'==c){
					q.push(pii(i,j));
					dist[c][i][j]=0;
				}
				else dist[c][i][j]=INF;
			}
		}
		while(!q.empty()){
			pii u=q.front();
			q.pop();
			for(int o=0;o<4;o++){
				int nx=u.first+dx[o],ny=u.second+dy[o];
				if(nx<0 || nx>=n || ny<0 || ny>=m || s[nx][ny]=='#' || dist[c][nx][ny]<INF)continue;
				q.push(pii(nx,ny));
				dist[c][nx][ny]=dist[c][u.first][u.second]+1;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ans=min(ans,dist[0][i][j]+dist[1][i][j]+dist[2][i][j]-2);
		}
	}
	cout<<(ans==INF-2?-1:ans)<<endl;
	return 0;
}


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
using namespace std;
const int N=152;
int n,t,s,a[N],dp[N][N*N],ans=INF;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>t>>s;
	s=min(s,n*(n-1)/2);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	setINF(dp);
	dp[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=i-1;j>=0;j--){
			for(int k=0;k<=i*j;k++){
				if(dp[j][k]==INF)continue;
				dp[j+1][k+i-j-1]=min(dp[j+1][k+i-j-1],dp[j][k]+a[i]);
			}
		}
	}
	for(int i=0;i<=s;i++){
		ans=min(ans,dp[t][i]);
	}
	cout<<ans<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>

#ifdef LOCAL_RUN
#include "debug.hpp"
#else
#define Debug(...)
#endif

using namespace std;

typedef long long int64;

const int kMaxN = 155, inf = 0x3f3f3f3f;

int left_dp[2][kMaxN][kMaxN * kMaxN];
int right_dp[2][kMaxN][kMaxN * kMaxN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k, s; cin >> n >> k >> s;

    vector<int> els(n);

    for (int i = 0; i < n; i += 1) {
        cin >> els[i];
    }

    for (int j = 0; j <= n; j += 1) {
        for (int l = 0; l <= n * n; l += 1) {
            right_dp[0][j][l] = +inf;
            right_dp[0][0][l] = 0;
        }
    }

    for (int i = k - 1; i >= 0; i -= 1) {
        for (int num_taken = 0; num_taken <= k - 1 - i; num_taken += 1) {
            for (int swaps = 0; swaps <= k * k; swaps += 1) {
                left_dp[1][num_taken][swaps] = left_dp[0][num_taken][swaps];
            }
        }

        for (int num_taken = 0; num_taken <= k - 1 - i; num_taken += 1) {
            for (int swaps = 0; swaps <= k * k; swaps += 1) {
                int swap_here = k - 1 - i - num_taken;
                auto& c = left_dp[0][num_taken + 1][swaps + swap_here];
                c = max(c, els[i] + left_dp[1][num_taken][swaps]);
                c = max(c, left_dp[1][num_taken + 1][swaps + swap_here]);
            }
        }
    }

    for (int i = k; i < n; i += 1) {
        for (int num_taken = 0; num_taken <= i - k + 1; num_taken += 1) {
            for (int swaps = 0; swaps <= (n - k) * (n - k); swaps += 1) {
                right_dp[1][num_taken][swaps] = right_dp[0][num_taken][swaps];
            }
        }

        for (int num_taken = 0; num_taken <= i - k; num_taken += 1) {
            for (int swaps = 0; swaps <= (n - k) * (n - k); swaps += 1) {
                int swap_here = i - k - num_taken;
                auto& c = right_dp[0][num_taken + 1][swaps + swap_here];
                c = min(c, els[i] + right_dp[1][num_taken][swaps]);
                c = min(c, right_dp[1][num_taken + 1][swaps + swap_here]);
            }
        }
    }

    // merge the 2 dps
    int left_sum = 0;
    for (int i = 0; i < k; i += 1) {
        left_sum += els[i];
    }

    int ans = +inf;
    for (int num_taken = 0; num_taken <= k; num_taken += 1) {
        int remaining_swaps = s - num_taken * num_taken;
        if (remaining_swaps < 0) {
            continue;
        }

        for (int left_swaps = 0; left_swaps <= k * k; left_swaps += 1) {
            for (int right_swaps = 0; right_swaps <= (n - k) * (n - k); right_swaps += 1) {
                int c_swaps = remaining_swaps - left_swaps - right_swaps;
                if (c_swaps < 0) {
                    break;
                }

//                Debug(left_sum, num_taken, left_swaps, right_swaps, left_dp[0][num_taken][left_swaps], right_dp[0][num_taken][right_swaps]);
                ans = min(ans, left_sum - left_dp[0][num_taken][left_swaps] + right_dp[0][num_taken][right_swaps]);
            }
        }
    }

    cout << ans << '\n';

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>

#ifdef LOCAL_RUN
#include "debug.hpp"
#else
#define Debug(...)
#endif

using namespace std;

typedef long long int64;

const int kMaxN = 155, inf = 0x3f3f3f3f;

int left_dp[2][kMaxN][kMaxN * kMaxN];
int right_dp[2][kMaxN][kMaxN * kMaxN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k, s; cin >> n >> k >> s;

    vector<int> els(n);

    for (int i = 0; i < n; i += 1) {
        cin >> els[i];
    }

    for (int j = 0; j <= n; j += 1) {
        for (int l = 0; l <= n * n; l += 1) {
            right_dp[0][j][l] = +inf;
            right_dp[0][0][l] = 0;
        }
    }

    for (int i = k - 1; i >= 0; i -= 1) {
        for (int num_taken = 0; num_taken <= k - 1 - i; num_taken += 1) {
            for (int swaps = 0; swaps <= k * k; swaps += 1) {
                left_dp[1][num_taken][swaps] = left_dp[0][num_taken][swaps];
            }
        }

        for (int num_taken = 0; num_taken <= k - 1 - i; num_taken += 1) {
            for (int swaps = 0; swaps <= k * k; swaps += 1) {
                int swap_here = k - 1 - i - num_taken;
                auto& c = left_dp[0][num_taken + 1][swaps + swap_here];
                c = max(c, els[i] + left_dp[1][num_taken][swaps]);
                c = max(c, left_dp[1][num_taken + 1][swaps + swap_here]);
            }
        }
    }

    for (int i = k; i < n; i += 1) {
        for (int num_taken = 0; num_taken <= i - k + 1; num_taken += 1) {
            for (int swaps = 0; swaps <= (n - k) * (n - k); swaps += 1) {
                right_dp[1][num_taken][swaps] = right_dp[0][num_taken][swaps];
            }
        }

        for (int num_taken = 0; num_taken <= i - k; num_taken += 1) {
            for (int swaps = 0; swaps <= (n - k) * (n - k); swaps += 1) {
                int swap_here = i - k - num_taken;
                auto& c = right_dp[0][num_taken + 1][swaps + swap_here];
                c = min(c, els[i] + right_dp[1][num_taken][swaps]);
                c = min(c, right_dp[1][num_taken + 1][swaps + swap_here]);
            }
        }
    }

    // merge the 2 dps
    int left_sum = 0;
    for (int i = 0; i < k; i += 1) {
        left_sum += els[i];
    }

    int ans = +inf;
    for (int num_taken = 0; num_taken <= k; num_taken += 1) {
        int remaining_swaps = k - num_taken * num_taken;
        if (remaining_swaps < 0) {
            continue;
        }

        for (int left_swaps = 0; left_swaps <= k * k; left_swaps += 1) {
            for (int right_swaps = 0; right_swaps <= (n - k) * (n - k); right_swaps += 1) {
                int c_swaps = remaining_swaps - left_swaps - right_swaps;
                if (c_swaps < 0) {
                    break;
                }

                ans = min(ans, left_sum - left_dp[0][num_taken][left_swaps] + right_dp[0][num_taken][right_swaps]);
            }
        }
    }

    cout << ans << '\n';

    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MN 150
#define MX 5625
int f[MN+5][MX+5];
int main()
{
	int n,m,s,x,i,j,k;
	scanf("%d%d%d",&n,&m,&s);
	memset(f,40,sizeof(f));
	for(i=0;i<=s&&i<=MX;++i)f[0][i]=0;
	for(i=1;i<=n;++i)
	{
		scanf("%d",&x);
		for(j=min(i,m);j;--j)for(k=i-j;k<=s&&k<=MX;++k)f[j][k]=min(f[j][k],f[j-1][k-i+j]+x);
	}
	printf("%d",f[m][s]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MN 150
#define MX 5625
int f[MN+5][MX+5];
int main()
{
	int n,m,s,x,i,j,k;
	scanf("%d%d%d",&n,&m,&s);
	memset(f,40,sizeof(f));
	for(i=0;i<=s&&i<=MX;++i)f[0][i]=0;
	for(i=1;i<=n;++i)
	{
		scanf("%d",&x);
		for(j=min(i,m);j;--j)for(k=i-j;k<=s&&k<=MX;++k)
			f[j][k]=min(f[j][k],f[j-1][k-i+j]+x);
	}
	printf("%d",f[m][min(s,MX)]);
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=155;
const ll inf=(ll)1e10;
ll dp[2][N][N*N],a[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,k,s,i,j,sum;
  cin>>n>>k>>s;
  rep(i,1,n+1)
    cin>>a[i];
  rep(i,0,k+1)
    rep(j,0,2)
    rep(sum,0,n*n+1)
    dp[j][i][sum]=inf;
  dp[0][0][0]=0;
  int state=0;
  rep(i,1,n+1)
    {
      state=1-state;
      rep(j,0,k+1)
	{
	  rep(sum,0,n*n+1)
	    {
	      dp[state][j][sum]=dp[1-state][j][sum];
	      if(sum>=i && j>=1)
		dp[state][j][sum]=min(dp[state][j][sum],dp[1-state][j-1][sum-i]+a[i]);
	    }
	}
      rep(j,1,k+1)
	rep(sum,0,n*n+1)
	dp[1-state][j][sum]=inf;
    }
  int rem=(k*(k+1))/2+s;
  ll ans=inf;
  rep(sum,0,min(n*n,rem)+1)
    ans=min(ans,dp[(n&1)][k][sum]);
  cout<<ans<<endl;
  return 0 ;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=155;
const ll inf=(ll)1e10;
ll dp[2][N][N*N],a[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,k,s,i,j,sum;
  cin>>n>>k>>s;
  rep(i,1,n+1)
    cin>>a[i];
  rep(i,0,k+1)
    rep(j,0,2)
    rep(sum,0,n*n+1)
    dp[j][i][sum]=inf;
  dp[0][0][0]=0;
  int state=0;
  rep(i,1,n+1)
    {
      state=1-state;
      rep(j,0,k+1)
	{
	  rep(sum,0,n*n+1)
	    {
	      dp[state][j][sum]=dp[1-state][j][sum];
	      if(sum>=i && j>=1)
		dp[state][j][sum]=min(dp[state][j][sum],dp[1-state][j-1][sum-i]+a[i]);
	    }
	}
      rep(j,1,k+1)
	rep(sum,0,n*n+1)
	dp[1-state][j][sum]=inf;
    }
  int rem=(k*(k+1))/2+s;
  ll ans=inf;
  rep(sum,0,rem+1)
    ans=min(ans,dp[(n&1)][k][sum]);
  cout<<ans<<endl;
  return 0 ;
}


#include <bits/stdc++.h>
#define LL long long

using namespace std;

void load() {
    #ifndef ONLINE_JUDGE
    freopen(".inp","r",stdin);
    freopen(".out","w",stdout);
    #endif // ONLINE_JUDGE
}

const int N = 155;
LL dp[N][N*N],G[N][N*N];
int a[N];

void trungtt() {
    int n,k,s;
    scanf("%d%d%d",&n,&k,&s);
    for (int i = 1 ; i <= n ; ++ i) scanf("%d",&a[i]);
    if (s > n*(n-1)/2) {
        sort(a+1,a+1+n);
        LL sum = 0;
        for (int i = 1 ; i <= k ; ++ i)
            sum += a[i];
        printf("%lld",sum);
        return;
    }

    for (int i = 1 ; i <= k; ++ i)
    for (int j = 0 ; j <= s ; ++ j)
        dp[i][j] = 1e18;
    for (int i = 1 ; i <= n ; ++ i) {
        for (int j = 1 ; j <= min(k,i); ++ j)
            for (int h = 0 ; h <= s ; ++ h)
                G[j][h] = 1e18;
        for (int j = 1 ; j <= min(k,i) ; ++ j)
            for (int h = 0 ; h <= s ; ++ h)
                if (h-i+j >= 0) G[j][h] = min(G[j][h],dp[j-1][h-i+j] + a[i]);

        for (int j = 0 ; j <= min(k,i) ; ++ j)
            for (int h = 0 ; h <= s; ++ h)
                dp[j][h] = min(dp[j][h],G[j][h]);
    }
    LL ans = 1e18;
    for (int i = 0 ; i <= s; ++ i)
        ans = min(ans,dp[k][i]);
    printf("%lld",ans);
    return ;
}

int main() {
    load();
    trungtt();
    return 0;
}


#include<bits/stdc++.h>

const int N = 160;
const int M = N * N;

int dp[N][M];
int q[N];

int main(){
    int n, k, s;
    scanf("%d%d%d", &n, &k, &s);
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 1, x; i <= n; ++ i){
        scanf("%d", &x);
        for (int j = i - 1; j >= 0; -- j){
            for (int kk = 0; kk < M; ++ kk){
                if (dp[j][kk] == -1) continue;
                int &u = dp[j + 1][kk + i];
                if (u == -1 || u > dp[j][kk] + x){
                    u = dp[j][kk] + x;
                }
            }
        }
    }
    int min = INT_MAX;
    for (int i = 0; i < M; ++ i){
        if (dp[k][i] == -1) continue;
        if (i - k * (k + 1) / 2 > s) break;
        min = std::min(min, dp[k][i]);
    }
    printf("%d\n", min);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define f first
#define s second
#define pb push_back
#define PII pair<ll,ll>
ll const MOD = 1000000007;
ll const N = 1000005;
ll const LN = 20;
ll const inf = 8e18;
using namespace std;

ll n, m, a[N];

ll dp[2][152][22502];

int main()
{
	ios::sync_with_stdio (false);
	cin.tie (NULL);
	ll n, kk, s;
	cin >> n >> kk >> s;
	for (ll i = 1; i <= n; i++)
		cin >> a[i];
	for (ll i = 0; i <= n; i++)
	{
		for (ll j = 0; j <= n * n; j++)
			dp[0][i][j] = dp[1][i][j] = inf;
	}
	ll u = 0, v = 1;
	for (ll i = 0; i <= n * n; i++)
		dp[u][0][i] = 0;
	for (ll i = 1; i <= n; i++)
	{
		for (ll k = 0; k <= n; k++)
			for (ll j = 0; j <= n * n; j++)
				dp[v][k][j] = inf;
		for (ll k = 0; k <= n; k++)
		{
			for (ll j = 0; j <= n * n; j++)
			{
				dp[v][k][j] = min (dp[v][k][j], dp[u][k][j]);
				if (j >= i && k && dp[u][k - 1][j - i] != inf)
					dp[v][k][j] = min (dp[v][k][j], dp[u][k - 1][j - i] + a[i]);
			}
		}
		swap (u, v);
	}
	ll ans = inf;
	for (ll i = 0; i <= min (s + (kk * (kk + 1)) / 2, n * n); i++)
		ans = min (ans, dp[u][kk][i]);
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define f first
#define s second
#define pb push_back
#define PII pair<ll,ll>
ll const MOD = 1000000007;
ll const N = 1000005;
ll const LN = 20;
ll const inf = 8e18;
using namespace std;

ll n, m, a[N];

ll dp[2][150][22502];

int main()
{
	ios::sync_with_stdio (false);
	cin.tie (NULL);
	ll n, kk, s;
	cin >> n >> kk >> s;
	for (ll i = 1; i <= n; i++)
		cin >> a[i];
	for (ll i = 0; i <= n; i++)
	{
		for (ll j = 0; j <= n * n; j++)
			dp[0][i][j] = dp[1][i][j] = inf;
	}
	ll u = 0, v = 1;
	for (ll i = 0; i <= n * n; i++)
		dp[u][0][i] = 0;
	for (ll i = 1; i <= n; i++)
	{
		for (ll k = 0; k <= n; k++)
			for (ll j = 0; j <= n * n; j++)
				dp[v][k][j] = inf;
		for (ll k = 0; k <= n; k++)
		{
			for (ll j = 0; j <= n * n; j++)
			{
				dp[v][k][j] = min (dp[v][k][j], dp[u][k][j]);
				if (j >= i && k && dp[u][k - 1][j - i] != inf)
					dp[v][k][j] = min (dp[v][k][j], dp[u][k - 1][j - i] + a[i]);
			}
		}
		swap (u, v);
	}
	ll ans = inf;
	for (ll i = 0; i <= min (s + (kk * (kk + 1)) / 2, n * n); i++)
		ans = min (ans, dp[u][kk][i]);
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 151;
const int INF = 1e9 + 7;
int n, k, s;
int dp[N][N * N];
int a[N];
void read() {
    cin >> n >> k >> s;
    for (int i = 0; i < n; ++i) cin >> a[i];
}
void solve() {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N * N; ++j) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = min(i + 1, k); j >= 1; --j) {
            int sw = i - (j - 1);
            for (int t = sw; t < N * N; ++t) {
                dp[j][t] = min(dp[j][t], dp[j - 1][t - sw] + a[i]);
            }
        }
    }
}
void print() {
    int ans = INF;
    for (int i = 0; i <= s; ++i) {
        ans = min(ans, dp[k][i]);
    }
    cout << ans << '\n';
}
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(20);
    #endif
    read();
    solve();
    print();
}


#include<bits/stdc++.h>
using namespace std;
const int N = 151;
const int INF = 1e9 + 7;
int n, k, s;
int dp[N][N * N];
int a[N];
void read() {
    cin >> n >> k >> s;
    for (int i = 0; i < n; ++i) cin >> a[i];
}
void solve() {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N * N; ++j) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = min(i + 1, k); j >= 1; --j) {
            int sw = i - (j - 1);
            for (int t = sw; t < N * N; ++t) {
                dp[j][t] = min(dp[j][t], dp[j - 1][t - sw] + a[i]);
            }
        }
    }
}
void print() {
    int ans = INF;
    for (int i = 0; i <= s && i < N * N; ++i) {
        ans = min(ans, dp[k][i]);
    }
    cout << ans << '\n';
}
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(20);
    #endif
    read();
    solve();
    print();
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;

const int MX=400;
const int mod=1e9+7;
const int inf=1e18;

#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
int dp[5630][11180],a[200];
int m,n;
int ok(int l, int r, int mov)
{
    if(l>m)return 0;
    if(r<=m) return a[l]+ok(l+1,r,mov);
    int p=(n-r)*m+l;
    if(~dp[p][mov])return dp[p][mov];
    int mn=1e9;
    mn=min(mn,a[l]+ok(l+1,r,mov));
    mn=min(mn,ok(l,r-1,mov));
    if(mov>=(r-l)) mn=min(mn,a[r]+ok(l+1,r-1,mov-(r-l)));
    return dp[p][mov]=mn;
}
int main()
{

    //FasterIO;
    int i,j,k,s,tc,cs=1;
    scanf("%d%d%d",&n,&m,&s);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    if(s>(n*(n+1))/2)s=(n*(n+1))/2;
    mem(dp,-1);
    int res=ok(1,n,s);
    printf("%d\n",res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;

const int MX=400;
const int mod=1e9+7;
const int inf=1e18;

#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
int dp[6000][11180],a[200];
int m,n;
int ok(int l, int r, int mov)
{
    if(l>m)return 0;
    if(r<=m) return a[l]+ok(l+1,r,mov);
    int p=(n-r)*m+l;
    if(~dp[p][mov])return dp[p][mov];
    int mn=1e9;
    mn=min(mn,a[l]+ok(l+1,r,mov));
    mn=min(mn,ok(l,r-1,mov));
    if(mov>=(r-l)) mn=min(mn,a[r]+ok(l+1,r-1,mov-(r-l)));
    return dp[p][mov]=mn;
}
int main()
{

    //FasterIO;
    int i,j,k,s,tc,cs=1;
    scanf("%d%d%d",&n,&m,&s);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    if(s>(n*(n+1))/2)s=(n*(n+1))/2;
    mem(dp,-1);
    int res=ok(1,n,s);
    printf("%d\n",res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;

const int MX=400;
const int mod=1e9+7;
const int inf=1e18;

#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
int dp[1000][40000],a[200];
int var=3,m;
int ok(int l, int r, int mov)
{
    if(l>m)return 0;
    if(r<=m) return a[l]+ok(l+1,r,mov);
    int p=(r-l)*var+l;
    if(~dp[p][mov])return dp[p][mov];
    int mn=1e9;
    mn=min(mn,a[l]+ok(l+1,r,mov));
    if(mov>=(r-l))
    {
        mn=min(mn,ok(l,r-1,mov));
        mn=min(mn,a[r]+ok(l+1,r-1,mov-(r-l)));
    }
    return dp[p][mov]=mn;
}
int main()
{

    //FasterIO;
    int i,j,k,n,s,tc,cs=1;
    scanf("%d%d%d",&n,&m,&s);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    if(s>(n*(n+1))/2)s=(n*(n+1))/2;
    mem(dp,-1);
    int res=ok(1,n,s);
    printf("%d\n",res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;

const int MX=400;
const int mod=1e9+7;
const int inf=1e18;

#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
int dp[6000][22500],a[200];
int m,n;
int ok(int l, int r, int mov)
{
    if(l>m)return 0;
    if(r<=m) return a[l]+ok(l+1,r,mov);
    int p=(n-r)*m+l;
    if(~dp[p][mov])return dp[p][mov];
    int mn=1e9;
    mn=min(mn,a[l]+ok(l+1,r,mov));
    mn=min(mn,ok(l,r-1,mov));
    if(mov>=(r-l)) mn=min(mn,a[r]+ok(l+1,r-1,mov-(r-l)));
    return dp[p][mov]=mn;
}
int main()
{

    //FasterIO;
    int i,j,k,s,tc,cs=1;
    scanf("%d%d%d",&n,&m,&s);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    if(s>(n*(n+1))/2)s=(n*(n+1))/2;
    mem(dp,-1);
    int res=ok(1,n,s);
    printf("%d\n",res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;

const int MX=400;
const int mod=1e9+7;
const int inf=1e18;

#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
int dp[4500][11175],a[200];
int m,n;
int ok(int l, int r, int mov)
{
    if(l>m)return 0;
    if(r<=m) return a[l]+ok(l+1,r,mov);
    int p=(n-r)*m+l;
    if(~dp[p][mov])return dp[p][mov];
    int mn=1e9;
    mn=min(mn,a[l]+ok(l+1,r,mov));
    mn=min(mn,ok(l,r-1,mov));
    if(mov>=(r-l)) mn=min(mn,a[r]+ok(l+1,r-1,mov-(r-l)));
    return dp[p][mov]=mn;
}
int main()
{

    //FasterIO;
    int i,j,k,s,tc,cs=1;
    scanf("%d%d%d",&n,&m,&s);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    if(s>(n*(n+1))/2)s=(n*(n+1))/2;
    mem(dp,-1);
    int res=ok(1,n,s);
    printf("%d\n",res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;

const int MX=400;
const int mod=1e9+7;
const int inf=1e18;

#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
int dp[5000][11500],a[200];
int m,n;
int ok(int l, int r, int mov)
{
    if(l>m)return 0;
    if(r<=m) return a[l]+ok(l+1,r,mov);
    int p=(n-r)*m+l;
    if(~dp[p][mov])return dp[p][mov];
    int mn=1e9;
    mn=min(mn,a[l]+ok(l+1,r,mov));
    mn=min(mn,ok(l,r-1,mov));
    if(mov>=(r-l)) mn=min(mn,a[r]+ok(l+1,r-1,mov-(r-l)));
    return dp[p][mov]=mn;
}
int main()
{

    //FasterIO;
    int i,j,k,s,tc,cs=1;
    scanf("%d%d%d",&n,&m,&s);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    if(s>(n*(n+1))/2)s=(n*(n+1))/2;
    mem(dp,-1);
    int res=ok(1,n,s);
    printf("%d\n",res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;

const int MX=400;
const int mod=1e9+7;
const int inf=1e18;

#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
int dp[1000][40000],a[200];
int var=3,m;
int ok(int l, int r, int mov)
{
    if(l>m)return 0;
    if(r<=m) return a[l]+ok(l+1,r,mov);
    int p=(r-l)*var+l;
    if(~dp[p][mov])return dp[p][mov];
    int mn=1e9;
    mn=min(mn,a[l]+ok(l+1,r,mov));
    mn=min(mn,ok(l,r-1,mov));
    if(mov>=(r-l)) mn=min(mn,a[r]+ok(l+1,r-1,mov-(r-l)));
    return dp[p][mov]=mn;
}
int main()
{

    //FasterIO;
    int i,j,k,n,s,tc,cs=1;
    scanf("%d%d%d",&n,&m,&s);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    if(s>(n*(n+1))/2)s=(n*(n+1))/2;
    mem(dp,-1);
    int res=ok(1,n,s);
    printf("%d\n",res);
    return 0;
}


#include <iostream>
using namespace std;

int n, kk, s;

const int inf = 1e9;

struct d {
	int l, r, a; //левая и правая границы и значение в дп
};

int main() {
	cin >> n >> kk >> s;
	s = min(s, 12000);
	int a[n + 1], sum = 0;
	a[0] = inf;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= kk; i++) sum += a[i];
	d dp[s + 1];
	dp[0] = {kk + 1, kk, 0}; //прост
	for(int i = 1; i <= s; i++) { //текущий "вес"
		dp[i] = dp[i - 1];
		for(int j = kk; j > 0; j--) { //делаем полный перебор вариантов
			for(int k = kk + 1; k <= n and k - j <= i; k++) {
				if(dp[i].a > dp[i - k + j].a + a[k] - a[j]) { //если наткнулись на хорошее значение
					if(k > dp[i - k + j].r and j < dp[i - k + j].l) { //только если границы подходящие
						dp[i].a = dp[i - k + j].a + a[k] - a[j]; //прибавляем что-то новое из правой части и удаляем что-то старое из левой
						dp[i].l = j;
						dp[i].r = k;
					}
				}
			}
		}
	}
	cout << sum + dp[s].a << endl; //ну, собственно, в конце получаем какой-то (большой) минус и отнимаем его от наших первых k
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

// 	835 811 807 792
// 1.	835 807 811 792
// 2.  807 835 811 792
// 3.  807 835 792 811
// 4.  807 792 835 811

int n, kk, s;

const int inf = 1e9;

struct d {
	int l, r, a; //левая и правая границы и значение в дп
};

int main() {
	cin >> n >> kk >> s;
	int a[n + 1], b[n + 1], sum = 0, sum1 = 0;
	a[0] = inf;
	for(int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
	b[0] = inf;
	sort(b, b + n + 1);
	for(int i = 1; i <= kk; i++) sum += a[i], sum1 += b[i];
	if(s >= n * n) {
		cout << sum1 << endl;
		return 0;
	}
	s = min(s, 12000);
	d dp[s + 1];
	dp[0] = {kk + 1, kk, 0}; //прост
	for(int i = 1; i <= s; i++) { //текущий "вес"
		dp[i].a = dp[i - 1].a;
		for(int j = kk; j > 0; j--) { //делаем полный перебор вариантов
			for(int k = kk + 1; k <= n and k - j <= i; k++) {
				if(dp[i].a > dp[i - k + j].a + a[k] - a[j]) { //если наткнулись на хорошее значение
					if(k > dp[i - k + j].r and j < dp[i - k + j].l) { //только если границы подходящие
						dp[i].a = dp[i - k + j].a + a[k] - a[j]; //прибавляем что-то новое из правой части и удаляем что-то старое из левой
						dp[i].l = j;
						dp[i].r = k;
					}
				}
			}
		}
	}
	// cout << -835 + 807 + 792 - 855 << endl;
	// for(int i = 1; i <= 100; i++) {
	// 	cout << dp[i].l << ' ' << dp[i].r << ' ' << dp[i].a << endl;
	// }
	cout << sum + dp[s].a << endl; //ну, собственно, в конце получаем какой-то (большой) минус и отнимаем его от наших первых k
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

// 	835 811 807 792
// 1.	835 807 811 792
// 2.  807 835 811 792
// 3.  807 835 792 811
// 4.  807 792 835 811

int n, kk, s;

const int inf = 1e9;

struct d {
	int l, r, a; //левая и правая границы и значение в дп
};

int main() {
	cin >> n >> kk >> s;
	s = min(s, 12000);
	int a[n + 1], b[n + 1], sum = 0, sum1 = 0;
	a[0] = inf;
	for(int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
	b[0] = inf;
	sort(b, b + n + 1);
	for(int i = 1; i <= kk; i++) sum += a[i], sum1 += b[i - 1];
	if(s >= n * n) {
		cout << sum1 << endl;
		return 0;
	}
	d dp[s + 1];
	dp[0] = {kk + 1, kk, 0}; //прост
	for(int i = 1; i <= s; i++) { //текущий "вес"
		dp[i] = dp[i - 1];
		for(int j = kk; j > 0; j--) { //делаем полный перебор вариантов
			for(int k = kk + 1; k <= n and k - j <= i; k++) {
				if(dp[i].a > dp[i - k + j].a + a[k] - a[j]) { //если наткнулись на хорошее значение
					if(k > dp[i - k + j].r and j < dp[i - k + j].l) { //только если границы подходящие
						dp[i].a = dp[i - k + j].a + a[k] - a[j]; //прибавляем что-то новое из правой части и удаляем что-то старое из левой
						dp[i].l = j;
						dp[i].r = k;
					}
				}
			}
		}
	}
	// cout << -835 + 807 + 792 - 855 << endl;
	// for(int i = 1; i <= 100; i++) {
	// 	cout << dp[i].l << ' ' << dp[i].r << ' ' << dp[i].a << endl;
	// }
	cout << sum + dp[s].a << endl; //ну, собственно, в конце получаем какой-то (большой) минус и отнимаем его от наших первых k
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

// 	835 811 807 792
// 1.	835 807 811 792
// 2.  807 835 811 792
// 3.  807 835 792 811
// 4.  807 792 835 811

int n, kk, s;

const int inf = 1e9;

struct d {
	int l, r, a; //левая и правая границы и значение в дп
};

int main() {
	cin >> n >> kk >> s;
	s = min(s, 12000);
	int a[n + 1], b[n + 1], sum = 0, sum1 = 0;
	a[0] = inf;
	for(int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
	b[0] = inf;
	sort(b, b + n + 1);
	for(int i = 1; i <= kk; i++) sum += a[i], sum1 += b[i];
	if(s >= n * n) {
		cout << sum1 << endl;
		return 0;
	}
	d dp[s + 1];
	dp[0] = {kk + 1, kk, 0}; //прост
	for(int i = 1; i <= s; i++) { //текущий "вес"
		dp[i] = dp[i - 1];
		for(int j = kk; j > 0; j--) { //делаем полный перебор вариантов
			for(int k = kk + 1; k <= n and k - j <= i; k++) {
				if(dp[i].a > dp[i - k + j].a + a[k] - a[j]) { //если наткнулись на хорошее значение
					if(k > dp[i - k + j].r and j < dp[i - k + j].l) { //только если границы подходящие
						dp[i].a = dp[i - k + j].a + a[k] - a[j]; //прибавляем что-то новое из правой части и удаляем что-то старое из левой
						dp[i].l = j;
						dp[i].r = k;
					}
				}
			}
		}
	}
	// cout << -835 + 807 + 792 - 855 << endl;
	// for(int i = 1; i <= 100; i++) {
	// 	cout << dp[i].l << ' ' << dp[i].r << ' ' << dp[i].a << endl;
	// }
	cout << sum + dp[s].a << endl; //ну, собственно, в конце получаем какой-то (большой) минус и отнимаем его от наших первых k
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 152, INF = 1000000009;

int n, k, s;
int a[N];

int dp[N][N * N], ndp[N][N * N];
int main()
{
    cin >> n >> k >> s;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    s += (k * (k + 1)) / 2;
    s = min(s, (n * (n + 1)) / 2);
    for (int j = 0; j <= k; ++j)
    {
        for (int u = 0; u <= s; ++u)
            dp[j][u] = INF;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j <= k; ++j)
        {
            for (int u = 0; u <= s; ++u)
                ndp[j][u] = dp[j][u];
        }
        for (int j = 0; j <= k; ++j)
        {
            for (int u = 0; u <= s; ++u)
            {
                if (u + i <= s)
                    ndp[j + 1][u + i] = min(ndp[j + 1][u + i], dp[j][u] + a[i]);
            }
        }
        memcpy(dp, ndp, sizeof ndp);
    }
    int ans = INF;
    for (int u = 0; u <= s; ++u)
    {
        ans = min(ans, dp[k][u]);
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define    pf               printf
#define    PF(a)            printf("%d\n",(a))
#define    PF2(a,b)         printf("%d %d\n",(a), (b))
#define    PF3(a,b,c)       printf("%d %d %d\n",(a), (b), (c))
#define    PFL(a)           printf("%lld\n",(a))
#define    PFL2(a,b)        printf("%lld %lld\n",(a), (b))
#define    PFL3(a,b,c)      printf("%lld %lld %lld\n",(a), (b), (c))
#define    get(a)           cin>>a
#define    sf               scanf
#define    SF(a)            scanf("%d",&a)
#define    SF2(a,b)         scanf("%d %d",&a, &b)
#define    SF3(a,b,c)       scanf("%d %d %d",&a, &b, &c)
#define    SFL(a)           scanf("%lld",&a)
#define    SFL2(a,b)        scanf("%lld %lld",&a, &b)
#define    SFL3(a,b,c)      scanf("%lld %lld %lld",&a, &b, &c)
#define    gl(a)            getline(cin,(a))
#define    gc()             getchar()
#define    pb               push_back
#define    m_p              make_pair
#define    pc()             printf("Case %d: ",tt++)
#define    tc()             cout<<"Case "<<tt++<<": "
#define    SZ(a)            (int)(a).size()
#define    all(a)           a.begin(),a.end()
#define    FF               first
#define    SS               second
#define    MAX              2134567891
#define    MOD              1000000007
#define    MM               100005
#define    PI               2*acos(0.0)
#define    cond(n,m)        (xx>=0 && xx<(n) && yy>=0 && yy<(m))

#define    mem(a)           memset((a),0,sizeof (a))
#define    SET(a)           memset((a),-1,sizeof (a))
#define    output           freopen("output.txt","w",stdout);
#define    input            freopen("input.txt","r",stdin);
#define    I_O              ios_base::sync_with_stdio(0); cin.tie(0)
#define    rep(a)           for(int i=0;i<(a);i++)
#define    FOR(a,b)         for(int i=(a);i<(b);i++)
#define    REP(a)           for(int j=0;j<(a);j++)
#define    rev(a)           for(int i=(a);i>=0;i--)
#define    fr(i,n)          for(i=0;i<n;i++)
#define    fr1(i,n,m)       for(i=n;i<m;i++)

int dx[]  = {0, 0, 1, -1};
int dy[]  = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};

typedef long long ll;
typedef unsigned long long llu;
typedef priority_queue < int > PQ;
typedef pair < int, int > pi;
typedef pair < int, pi > pii;
typedef vector < int > vi;
typedef vector < ll > vl;
typedef vector < string > vs;

/*
//FUNCTION//
ll bigmod(ll a, ll b, ll c)
{
    if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=x*x%c;
    if(b%2==1)x=x*a%c;return x;
}

ll poww(ll a, ll b)
{
    if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=x*a;return x;
}

ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}

ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);}

int pr = 1000000;
vi primelist;
bool a[MM*10];
void seive( )
{
    int i,j,k=sqrt(pr);
    a[1]=1;
    primelist.pb(2);
    for(i=4;i<=pr;i+=2)a[i]=1;
    for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1;
    for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i);
}

ll fact_divs( ll n, ll p)
{
    ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt;
}
struct point{double x, y;};
double area( point A, point B, point C){
return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y);
}

//*/
int dp[2][155][11330];
int a[150];
int main()
{
    I_O;
    ll n,m,s;
    cin>>n>>m>>s;
    rep(n)cin>>a[i+1];
    int xr = 0;
    s = min(s,(n*(n+1)/2));
    for(int i=1;i<=m;i++)for(int j=0;j<=s;j++)dp[0][i][j] = MAX;
    for(int i=1;i<=m;i++)for(int j=0;j<=s;j++)dp[1][i][j] = MAX;
    dp[0][0][0] = 0;
    for(int i=1;i<=n;i++)
    {
        int nxr = xr^1;
        for(int j=1;j<=m;j++)
        {
            if(i<j)continue;
            int dist = i - j;
            for(int k=0;k<=s;k++)
            {
                dp[nxr][j][k] = dp[xr][j][k];
                if(k-dist>=0 && dp[xr][j-1][k-dist]!=MAX)
                {
                    dp[nxr][j][k] = min(dp[nxr][j][k],dp[xr][j-1][k-dist]+a[i]);

                }
            }
        }
        xr ^= 1;
    }
    int ans = MAX;
    for(int i=0;i<=s;i++)
    {

        if(dp[xr][m][i]!=MAX)ans = min(ans,dp[xr][m][i]);
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/


#include<bits/stdc++.h>

using namespace std;

#define    pf               printf
#define    PF(a)            printf("%d\n",(a))
#define    PF2(a,b)         printf("%d %d\n",(a), (b))
#define    PF3(a,b,c)       printf("%d %d %d\n",(a), (b), (c))
#define    PFL(a)           printf("%lld\n",(a))
#define    PFL2(a,b)        printf("%lld %lld\n",(a), (b))
#define    PFL3(a,b,c)      printf("%lld %lld %lld\n",(a), (b), (c))
#define    get(a)           cin>>a
#define    sf               scanf
#define    SF(a)            scanf("%d",&a)
#define    SF2(a,b)         scanf("%d %d",&a, &b)
#define    SF3(a,b,c)       scanf("%d %d %d",&a, &b, &c)
#define    SFL(a)           scanf("%lld",&a)
#define    SFL2(a,b)        scanf("%lld %lld",&a, &b)
#define    SFL3(a,b,c)      scanf("%lld %lld %lld",&a, &b, &c)
#define    gl(a)            getline(cin,(a))
#define    gc()             getchar()
#define    pb               push_back
#define    m_p              make_pair
#define    pc()             printf("Case %d: ",tt++)
#define    tc()             cout<<"Case "<<tt++<<": "
#define    SZ(a)            (int)(a).size()
#define    all(a)           a.begin(),a.end()
#define    FF               first
#define    SS               second
#define    MAX              2134567891
#define    MOD              1000000007
#define    MM               100005
#define    PI               2*acos(0.0)
#define    cond(n,m)        (xx>=0 && xx<(n) && yy>=0 && yy<(m))

#define    mem(a)           memset((a),0,sizeof (a))
#define    SET(a)           memset((a),-1,sizeof (a))
#define    output           freopen("output.txt","w",stdout);
#define    input            freopen("input.txt","r",stdin);
#define    I_O              ios_base::sync_with_stdio(0); cin.tie(0)
#define    rep(a)           for(int i=0;i<(a);i++)
#define    FOR(a,b)         for(int i=(a);i<(b);i++)
#define    REP(a)           for(int j=0;j<(a);j++)
#define    rev(a)           for(int i=(a);i>=0;i--)
#define    fr(i,n)          for(i=0;i<n;i++)
#define    fr1(i,n,m)       for(i=n;i<m;i++)

int dx[]  = {0, 0, 1, -1};
int dy[]  = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};

typedef long long ll;
typedef unsigned long long llu;
typedef priority_queue < int > PQ;
typedef pair < ll , ll > pi;
typedef pair < int , pi > pii;
typedef vector < int > vi;
typedef vector < ll > vl;
typedef vector < string > vs;

/*
//FUNCTION//
ll bigmod(ll a, ll b, ll c)
{
    if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=x*x%c;
    if(b%2==1)x=x*a%c;return x;
}

ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
ll poww(ll a, ll b)
{
    if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=x*a;return x;
}

ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);}

int pr = 10000000;
vi primelist;
bool a[MM*100];
void seive( )
{
    int i,j,k=sqrt(pr);
    a[1]=1;
    primelist.pb(2);
    for(i=4;i<=pr;i+=2)a[i]=1;
    for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1;
    for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i);
}

ll fact_divs( ll n, ll p)
{
    ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt;
}
struct point{double x, y;};
double area( point A, point B, point C){
return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y);
}

//*/
map < vector < ll>  , ll > dp[155][155];
ll n,k,s,a[150];
vector < ll > p;
ll dpcall(int id, int cnt, vector < ll > v)
{
    if(id>n)
    {
        if(cnt==k+1)
        {
            ll sum = 0;
            rep(v.size()) sum+= v[i];
            if(sum<=s)return 0;
            return 1e15;
        }
        return 1e15;
    }
    if(dp[id][cnt][v])return dp[id][cnt][v];
    dp[id][cnt][v] = dpcall(id+1,cnt,v);
    if(cnt<=k)
    {
        p = v;
        p.pb(id-cnt);
        dp[id][cnt][v] = min(dp[id][cnt][v],a[id]+dpcall(id+1,cnt+1,p));
    }

    return dp[id][cnt][v];
}
int main() {

    I_O;
    cin>>n>>k>>s;
    rep(n)cin>>a[i+1];
    vector < ll > v;
    cout<<dpcall(1,1,v)<<endl;
    return 0;
}
/*
3 2 2
2 4 1

*/


#include<bits/stdc++.h>

using namespace std;

#define    pf               printf
#define    PF(a)            printf("%d\n",(a))
#define    PF2(a,b)         printf("%d %d\n",(a), (b))
#define    PF3(a,b,c)       printf("%d %d %d\n",(a), (b), (c))
#define    PFL(a)           printf("%lld\n",(a))
#define    PFL2(a,b)        printf("%lld %lld\n",(a), (b))
#define    PFL3(a,b,c)      printf("%lld %lld %lld\n",(a), (b), (c))
#define    get(a)           cin>>a
#define    sf               scanf
#define    SF(a)            scanf("%d",&a)
#define    SF2(a,b)         scanf("%d %d",&a, &b)
#define    SF3(a,b,c)       scanf("%d %d %d",&a, &b, &c)
#define    SFL(a)           scanf("%lld",&a)
#define    SFL2(a,b)        scanf("%lld %lld",&a, &b)
#define    SFL3(a,b,c)      scanf("%lld %lld %lld",&a, &b, &c)
#define    gl(a)            getline(cin,(a))
#define    gc()             getchar()
#define    pb               push_back
#define    m_p              make_pair
#define    pc()             printf("Case %d: ",tt++)
#define    tc()             cout<<"Case "<<tt++<<": "
#define    SZ(a)            (int)(a).size()
#define    all(a)           a.begin(),a.end()
#define    FF               first
#define    SS               second
#define    MAX              2134567891
#define    MOD              1000000007
#define    MM               100005
#define    PI               2*acos(0.0)
#define    cond(n,m)        (xx>=0 && xx<(n) && yy>=0 && yy<(m))

#define    mem(a)           memset((a),0,sizeof (a))
#define    SET(a)           memset((a),-1,sizeof (a))
#define    output           freopen("output.txt","w",stdout);
#define    input            freopen("input.txt","r",stdin);
#define    I_O              ios_base::sync_with_stdio(0); cin.tie(0)
#define    rep(a)           for(int i=0;i<(a);i++)
#define    FOR(a,b)         for(int i=(a);i<(b);i++)
#define    REP(a)           for(int j=0;j<(a);j++)
#define    rev(a)           for(int i=(a);i>=0;i--)
#define    fr(i,n)          for(i=0;i<n;i++)
#define    fr1(i,n,m)       for(i=n;i<m;i++)

int dx[]  = {0, 0, 1, -1};
int dy[]  = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};

typedef long long ll;
typedef unsigned long long llu;
typedef priority_queue < int > PQ;
typedef pair < ll , ll > pi;
typedef pair < int , pi > pii;
typedef vector < int > vi;
typedef vector < ll > vl;
typedef vector < string > vs;

/*
//FUNCTION//
ll bigmod(ll a, ll b, ll c)
{
    if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=x*x%c;
    if(b%2==1)x=x*a%c;return x;
}

ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
ll poww(ll a, ll b)
{
    if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=x*a;return x;
}

ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);}

int pr = 10000000;
vi primelist;
bool a[MM*100];
void seive( )
{
    int i,j,k=sqrt(pr);
    a[1]=1;
    primelist.pb(2);
    for(i=4;i<=pr;i+=2)a[i]=1;
    for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1;
    for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i);
}

ll fact_divs( ll n, ll p)
{
    ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt;
}
struct point{double x, y;};
double area( point A, point B, point C){
return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y);
}

//*/
map < ll  , ll > dp[155][155];
ll n,k,s,a[155];
ll dpcall(int id, int cnt, ll sum)
{
    if(id>n)
    {
        if(cnt==k+1)
        {
            if(sum<=s)return 0;
            return 1e15;
        }
        return 1e15;
    }
    if(dp[id][cnt][sum])return dp[id][cnt][sum];
    dp[id][cnt][sum] = dpcall(id+1,cnt,sum);
    if(cnt<=k)
    {

        dp[id][cnt][sum] = min(dp[id][cnt][sum],a[id]+dpcall(id+1,cnt+1,sum+id-cnt));
    }

    return dp[id][cnt][sum];
}
int main() {

    I_O;

    cin>>n>>k>>s;
    rep(n)cin>>a[i+1];
    cout<<dpcall(1,1,0)<<endl;
    return 0;
}
/*
20 20 1000000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
*/


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,k,s,i,j,t,f[2][155][nmax],ans=inf,a[155];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k>>s;
	for(i=0;i<n;i++)cin>>a[i];
	//s+=k*(k-1)/2;
	s=min(s,n*(n-1)/2);
	for(i=0;i<2;i++)for(j=0;j<=k;j++)for(t=0;t<=s;t++)f[i][j][t]=inf;
	f[0][0][0]=0;
	for(i=0;i<n;i++)
	{
		int cur=i&1,nxt=cur^1;
		for(j=0;j<=min(k,i);j++)
		{
			for(t=0;t<=s;t++)
			 if(f[cur][j][t]!=inf)
			 {
				f[nxt][j][t]=min(f[nxt][j][t],f[cur][j][t]);
				f[nxt][j+1][t+i-j]=min(f[nxt][j+1][t+i-j],f[cur][j][t]+a[i]);
				f[cur][j][t]=inf;
			 }
		}
	}
	for(i=0;i<=s;i++)ans=min(ans,f[n&1][k][i]);
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;

const int N = 150 + 7;
int dig[N], n ,k, s;
int dp[N][N * N];
///-----
int main() {

    ///read
    scanf("%d%d%d", &n, &k, &s);
    rep(i, 1, n + 1) scanf("%d", &dig[i]);

    ///prework
    s = min(s, 80 * 80);
    memset(dp, 0x3f, sizeof(dp));
    rep(_s, 0, s + 1) dp[0][_s] = 0;

    ///work
    rep(i, 1, n + 1) {
        per(j, 1, i + 1) {
            rep(_s, 0, s + 1) if (_s + j - i >= 0) {
                dp[j][_s] = min(dp[j][_s], dp[j - 1][_s + j - i] + dig[i]);
            }
        }
    }

    ///print
    int ans = 0x3f3f3f3f;
    rep(_s, 0, s + 1) ans = min(ans, dp[k][_s]);
    cout << ans;

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
const int N = 152, inf = (1e6) * (150)+10, K = 5680;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int main(){
    scanf("%d %d %d", &n, &k, &s);
    s = min(s, n*(n-1));
    s = min(s, K-2);
    for(int i=1;i<=n;i++) scanf("%d", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=0;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1;
        pr = 1-nw;
        for(int j=0;j<=s;j++){
            for(int l=1;l<=k;l++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], min(inf, dp[pr][j-i+l][l-1]+A[i]));
                if(dp[nw][j][l]<0) dp[nw][j][l] = inf;
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%d", ans);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 152, inf = 1e9+10, K = 6e3+5;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int32_t main(){
    scanf("%lld %lld %lld", &n, &k, &s);
    s = min(s, n*(n-1));
    s = min(s, K-2);
    for(int i=1;i<=n;i++) scanf("%lld", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=0;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1;
        pr = 1-nw;
        for(int j=0;j<=s;j++){
            for(int l=1;l<=k;l++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], min(inf, dp[pr][j-i+l][l-1]+A[i]));
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%lld", ans);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 152, inf = (1e6) * (150)+10, K = 12e3;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int32_t main(){
    scanf("%lld %lld %lld", &n, &k, &s);
    s = min(s, n*(n-1)/2);
    s = min(s, K-2);
    for(int i=1;i<=n;i++) scanf("%lld", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=0;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1;
        pr = 1-nw;
        for(int l=1;l<=k;l++){
            for(int j=0;j<=s;j++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], (dp[pr][j-i+l][l-1]+A[i]));
                if(dp[nw][j][l]<0) dp[nw][j][l] = inf;
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%lld", ans);
}


#include<bits/stdc++.h>
using namespace std;
const int N = 152, inf = 1e9+10, K = 6e3+5;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int main(){
    scanf("%d %d %d", &n, &k, &s);
    s = min(s, n*(n-1));
    for(int i=1;i<=n;i++) scanf("%d", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=0;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1;
        pr = 1-nw;
        for(int j=0;j<=s;j++){
            for(int l=1;l<=k;l++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], dp[pr][j-i+l][l-1]+A[i]);
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%d", ans);
}


#include<bits/stdc++.h>
using namespace std;
const int N = 151, inf = 15e7+10, K = 10e3;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int main(){
    scanf("%d %d %d", &n, &k, &s);
    s = min(s, (n*(n-1)>>1));
    s = min(sm K-2);
    for(int i=1;i<=n;i++) scanf("%d", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=1;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1, pr = nw^1;
        for(int l=1;l<=min(k, i+1);l++){
            for(int j=0;j<=s;j++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], (dp[pr][j-i+l][l-1]+A[i]));
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%d", ans);
}


#include<bits/stdc++.h>
using namespace std;
const int N = 152, inf = 1e9+10, K = 6e3+5;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int main(){
    scanf("%d %d %d", &n, &k, &s);
    s = min(s, n*(n-1));
    s = min(s, K-2);
    for(int i=1;i<=n;i++) scanf("%d", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=0;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1;
        pr = 1-nw;
        for(int j=0;j<=s;j++){
            for(int l=1;l<=k;l++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], dp[pr][j-i+l][l-1]+A[i]);
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%d", ans);
}


#include<bits/stdc++.h>
using namespace std;
const int N = 152, inf = (1e6) * (150)+10, K = 6680;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int main(){
    scanf("%d %d %d", &n, &k, &s);
    s = min(s, n*(n-1));
    s = min(s, K-2);
    for(int i=1;i<=n;i++) scanf("%d", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=0;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1;
        pr = 1-nw;
        for(int j=0;j<=s;j++){
            for(int l=1;l<=k;l++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], min(inf, dp[pr][j-i+l][l-1]+A[i]));
                if(dp[nw][j][l]<0) dp[nw][j][l] = inf;
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%d", ans);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 152, inf = 1e9+10, K = 6e3+5;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int32_t main(){
    scanf("%lld %lld %lld", &n, &k, &s);
    s = min(s, n*(n-1));
    s = min(s, K-2);
    for(int i=1;i<=n;i++) scanf("%lld", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=0;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1;
        pr = 1-nw;
        for(int j=0;j<=s;j++){
            for(int l=1;l<=k;l++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], dp[pr][j-i+l][l-1]+A[i]);
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%lld", ans);
}


#include<bits/stdc++.h>
using namespace std;
const int N = 151, inf = 15e7+10, K = 10e3;
int dp[2][K][N], n, k, s, A[N], ans = inf, nw, pr;
int main(){
    scanf("%d %d %d", &n, &k, &s);
    s = min(s, (n*(n-1)>>1));
    for(int i=1;i<=n;i++) scanf("%d", &A[i]);
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) for(int l=1;l<N;l++) dp[i][j][l] = inf;
    for(int i=0;i<2;i++) for(int j=0;j<K;j++) dp[i][j][0] = 0;
    for(int i=1;i<=n;i++){
        nw = i&1, pr = nw^1;
        for(int l=1;l<=min(k, i+1);l++){
            for(int j=0;j<=s;j++){
                dp[nw][j][l] = dp[pr][j][l];
                if(j>=i-l) dp[nw][j][l] = min(dp[nw][j][l], (dp[pr][j-i+l][l-1]+A[i]));
            }
        }
    }
    nw = n&1;
    for(int i=0;i<=s;i++) ans = min(ans, dp[nw][i][k]);
    printf("%d", ans);
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K, S;
	cin >> N >> K >> S;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	S = min(S, (N - K) * K);
	int INF = (int)1 << 60;
	vector<vector<int> > dp(K + 1, vector<int>(S + 1, INF));
	vector<vector<int> > ndp(K + 1, vector<int>(S + 1, INF));
	dp[0][0] = 0;
	ndp[0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int k = 0; k < K&& i - k>=0; k++) {
			for (int s = 0; s + i - k <= S; s++) {
				if (dp[k][s] < INF) {
					ndp[k + 1][s + i - k] = min(dp[k + 1][s + i - k], dp[k][s] + A[i]);
				}
			}
		}
		dp = ndp;
	}
	int res = INF;
	for (int s = 0; s <= S; s++) {
		res = min(res, dp[K][s]);
	}
	cout << res << endl;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K, S;
	cin >> N >> K >> S;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	S = min(S, (N - K) * K);
	int INF = (int)1 << 60;
	vector<vector<int> > dp(K + 1, vector<int>(S + 1, INF));
	vector<vector<int> > ndp(K + 1, vector<int>(S + 1, INF));
	dp[0][0] = 0;
	ndp[0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int k = 0; k < K; k++) {
			for (int s = 0; s + i - k <= S; s++) {
				if (dp[k][s] < INF) {
					ndp[k + 1][s + i - k] = min(dp[k + 1][s + i - k], dp[k][s] + A[i]);
				}
			}
		}
		dp = ndp;
	}
	int res = INF;
	for (int s = 0; s <= S; s++) {
		res = min(res, dp[K][s]);
	}
	cout << res << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define pf                  printf
#define sc                  scanf
#define pb                  push_back
#define eb                  emplace_back
#define present(c,x)        ((c).find(x) != (c).end())
#define mp                  make_pair
#define xx                  first
#define yy                  second
#define endl                '\n'
#define SZ(v)               ((int) (v).size())
#define all(v)              (v).begin(), (v).end()
typedef long long           ll;
typedef long double         LD;
typedef unsigned long long  ull;
typedef pair<int,int>       pii;
const LD EPS =              1e-9;
const LD PI=                acos(-1.0);
const int MX=               6e5+5;
ll mod=                     1e9+7;

ll dp[2][155][155*155];
int main()
{
    int n,s,k;
    cin>>n>>k>>s;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    s=min(((n)*(n+1))/2,s);
    //cerr<<s<<endl;
   int del=n-k;

   for(int coin=0;coin<=s;coin++)
        dp[0][0][coin]=0;
    for(int d=1;d<=del;d++){
        for(int coin=0;coin<=s;coin++)
            dp[0][d][coin]=1e9;
    }

    int cur=1;

    for(int i=n-1;i>=0;i--){

        for(int coin=0;coin<=s;coin++){
            dp[cur][0][coin]=dp[cur^1][0][coin]+a[i];
            for(int d=1;d<=del;d++){
                dp[cur][d][coin]=dp[cur^1][d][coin]+a[i];
                int dd=del-d;
                int ii=i-dd;
                int cost=abs(ii-k+1);
                if(cost<=coin)
                    dp[cur][d][coin]=min(dp[cur][d][coin],
                        dp[cur^1][d-1][coin-cost]);

            }
        }
        cur^=1;
    }

    cout<<dp[cur^1][del][s]<<endl;

    return 0;
}

/**
                        Md. Tariqul Islam
                            IIT,JU
                          fb/tariqiitju
                      tarik.amtoly@gmail.com
*/


#include <bits/stdc++.h>
using namespace std;
#define pf                  printf
#define sc                  scanf
#define pb                  push_back
#define eb                  emplace_back
#define present(c,x)        ((c).find(x) != (c).end())
#define mp                  make_pair
#define xx                  first
#define yy                  second
#define endl                '\n'
#define SZ(v)               ((int) (v).size())
#define all(v)              (v).begin(), (v).end()
typedef long long           ll;
typedef long double         LD;
typedef unsigned long long  ull;
typedef pair<int,int>       pii;
const LD EPS =              1e-9;
const LD PI=                acos(-1.0);
const int MX=               6e5+5;
ll mod=                     1e9+7;

ll dp[2][155][155*155];
int main()
{
    int n,s,k;
    cin>>n>>k>>s;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    s=min(155*155-1,s);
   int del=n-k;

    for(int d=1;d<=del;d++){
        for(int coin=0;coin<=s;coin++)
            dp[0][d][coin]=0;
    }
    for(int coin=0;coin<=s;coin++)
            dp[0][0][coin]=1e9;

    int cur=1;

    for(int i=n-1;i>=0;i--){

        for(int coin=0;coin<=s;coin++){
            dp[cur][0][coin]=dp[cur^1][0][coin]+a[i];
            for(int d=1;d<=del;d++){
                dp[cur][d][coin]=dp[cur^1][d][coin]+a[i];
                int dd=del-d;///already deleted
                //if(dd>i)continue;

                int current_position_in_row=i-dd;
                int cost;
                if(current_position_in_row >= k)
                    cost=0;
                else
                    cost=k-current_position_in_row;

                if(cost<=coin )
                    dp[cur][d][coin]=min(dp[cur][d][coin],
                        dp[cur^1][d-1][coin-cost]);

            }
        }
        cur^=1;
    }

    cout<<dp[cur^1][del][s]<<endl;

    return 0;
}

/**
                        Md. Tariqul Islam
                            IIT,JU
                          fb/tariqiitju
                      tarik.amtoly@gmail.com
*/


#include <bits/stdc++.h>
using namespace std;
#define pf                  printf
#define sc                  scanf
#define pb                  push_back
#define eb                  emplace_back
#define present(c,x)        ((c).find(x) != (c).end())
#define mp                  make_pair
#define xx                  first
#define yy                  second
#define endl                '\n'
#define SZ(v)               ((int) (v).size())
#define all(v)              (v).begin(), (v).end()
typedef long long           ll;
typedef long double         LD;
typedef unsigned long long  ull;
typedef pair<int,int>       pii;
const LD EPS =              1e-9;
const LD PI=                acos(-1.0);
const int MX=               6e5+5;
ll mod=                     1e9+7;

ll dp[2][155][155*155];
int main()
{
    int n,s,k;
    cin>>n>>k>>s;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    s=min(155*155-1,s);
   int del=n-k;

    for(int d=1;d<=del;d++){
        for(int coin=0;coin<=s;coin++)
            dp[0][d][coin]=0;
    }
    for(int coin=0;coin<=s;coin++)
            dp[0][0][coin]=0;

    int cur=1;

    for(int i=n-1;i>=0;i--){

        for(int coin=0;coin<=s;coin++){
            //dp[cur][0][coin]=dp[cur^1][0][coin]+a[i];
            for(int d=0;d<=del;d++){
                int dd=del-d;///already deleted
                if(dd>i)continue;

                int current_position_in_row=i-dd;
                int cost;
                if(current_position_in_row<=k)
                    dp[cur][d][coin]=dp[cur^1][d][coin]+a[i];
                if(current_position_in_row >= k)
                    cost=0;
                else
                    cost=k-current_position_in_row;

                if(cost<=coin and d)
                    dp[cur][d][coin]=min(dp[cur][d][coin],
                        dp[cur^1][d-1][coin-cost]);

                // cerr<<i<<" toD: "<<d<<" deleted: "<<dd<<" coin: "<<
                // coin<<" positionInRow "<<current_position_in_row<<" cost: "<<cost<<" "
                // <<dp[cur][d][coin]<<endl;

            }
        }
        cur^=1;
    }

    cout<<dp[cur^1][del][s]<<endl;

    return 0;
}

/**
                        Md. Tariqul Islam
                            IIT,JU
                          fb/tariqiitju
                      tarik.amtoly@gmail.com
*/


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 150 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

int binom(int x){
	return x * (x - 1) / 2;
}

int a[maxN];
int dp[2][maxN][maxN * maxN];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	ll s; cin >> s;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	if (s > binom(n)){
		sort(a, a + n);
		ll sum = 0;
		for (int i = 0; i < k; i++){
			sum += a[i];
		}
		return cout << sum << endl, 0;
	}
	s += binom(k + 1);
	memset(dp, 63, sizeof dp);
	for (int i = 1; i <= n; i++){
		dp[i % 2][0][0] = 0;
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= k; j++){
			for (int m = 0; m <= s; m++){
				dp[i % 2][j][m] = dp[1 ^ (i % 2)][j][m];
				if (m != 0){
					dp[i % 2][j][m] = min(dp[i % 2][j][m], dp[i % 2][j][m - 1]);
				}
				if (m >= i){
					dp[i % 2][j][m] = min(dp[i % 2][j][m], dp[1 ^ (i % 2)][j - 1][m - i] + a[i - 1]);
				}
			}
		}
	}
	cout << dp[n % 2][k][s] << endl;
	return 0;
}


#include <iostream>

using namespace std;

const int N = 1000 * 1000 * 1000 + 7;
int dp[155][50005];
int a[155];
int main()
{
	int n, k, s;
	cin >> n;
	cin >> k;
	cin >> s;
	s = min(s, n * n / 2);
	s += k * (k + 1) / 2;
	int pyh = 0;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
	}

	for(int j = 1; j <= k; j ++)
	{
		for(int q = 0; q <= s; q ++)
		{
			dp[j][q] = N;
		}
	}
	for(int i = 1; i <= n; i ++)
	{
		for(int j = k; j >= 1; j --)
		{
			for(int q = 0; q <= s; q ++)
			{
				if(q >= i)
				{
					dp[j][q] = min(dp[j][q], dp[j - 1][q - i] + a[i]);
				}
			}
		}
	}
	int ans = N;
	for(int q = 0; q <= s; q ++)
	{
		//cout << dp[k][q] << " ";
		ans = min(ans, dp[k][q]);
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

vector<int> q;
#define MN 15
int dp[MN][MN][MN*MN];

int main () {
    int N, K, S;
    cin >> N >> K >> S;
    q.resize(N+1);
    for(int i=1;i<=N;i++) {
        cin >> q[i];
    }
    S = min(S, N*(N-1)/2);
    for(int i=N+1;i>=1;i--) {
        for(int k=0;k<=K;k++) {
            for(int s=0;s<=S;s++) {
                dp[i][k][s] = 1e9;
            }
        }
    }
    for(int s=0;s<=S;s++) {
        dp[N+1][K+1][s] = 0;
    }

    for(int i=N;i>=1;i--) {
        for(int k=0;k<=K;k++) {
            for(int s=0;s<=S;s++) {
                dp[i][k][s] = min(dp[i][k][s], dp[i+1][k][s]);
                if(s+abs(i-k) <= S) {
                    dp[i][k][s] = min(dp[i][k][s], q[i]+dp[i+1][k+1][s+abs(i-k)]);
                }
            }
        }
    }

    int ans = 1e9;
    for(int s=0;s<=S;s++) {
        ans = min(ans, dp[1][1][s]);
    }
    cout << ans;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> q;
#define MN 152
int dp[MN][MN][MN*MN];

int main () {
    int N, K, S;
    cin >> N >> K >> S;
    q.resize(N+1);
    for(int i=1;i<=N;i++) {
        cin >> q[i];
    }
    S = min(S, N*(N-1)/2);
    for(int i=N+1;i>=1;i--) {
        for(int k=0;k<=K;k++) {
            for(int s=0;s<=S;s++) {
                dp[i][k][s] = 1e9;
            }
        }
    }
    for(int s=0;s<=S;s++) {
        dp[N+1][K+1][s] = 0;
    }

    for(int i=N;i>=1;i--) {
        for(int k=0;k<=K;k++) {
            for(int s=0;s<=S;s++) {
                dp[i][k][s] = min(dp[i][k][s], dp[i+1][k][s]);
                if(s+abs(i-k) <= S) {
                    dp[i][k][s] = min(dp[i][k][s], q[i]+dp[i+1][k+1][s+abs(i-k)]);
                }
            }
        }
    }

    int ans = 1e9;
    for(int s=0;s<=S;s++) {
        ans = min(ans, dp[1][1][s]);
    }
    cout << ans;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> q;
#define MN 152
int dp[2][MN][MN*MN];

int main () {
    int N, K, S;
    cin >> N >> K >> S;
    q.resize(N+1);
    for(int i=1;i<=N;i++) {
        cin >> q[i];
    }
    S = min(S, N*(N-1)/2);
    for(int k=0;k<=K;k++) {
        for(int s=0;s<=S;s++) {
            dp[0][k][s] = dp[1][k][s] = 1e9;
        }
    }
    for(int s=0;s<=S;s++) {
        dp[(N+1)%2][K+1][s] = 0;
    }
    for(int i=N;i>=1;i--) {
        int l = i%2, r = (i+1)%2;
        for(int k=0;k<=K;k++) {
            for(int s=0;s<=S;s++) {
                dp[l][k][s] = min(dp[l][k][s], dp[r][k][s]);
                if(s+abs(i-k) <= S) {
                    dp[l][k][s] = min(dp[l][k][s], q[i]+dp[r][k+1][s+abs(i-k)]);
                }
            }
        }
        for(int k=0;k<=K;k++) {
            for(int s=0;s<=S;s++) {
                dp[r][k][s] = 1e9;
            }
        }
    }

    int ans = 1e9;
    for(int s=0;s<=S;s++) {
        ans = min(ans, dp[1][1][s]);
    }
    cout << ans;

    return 0;
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300);
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 155, maxs = maxn * maxn;
int n, k, s;
int a[maxn];

bool read() {
  if (scanf("%d%d%d", &n, &k, &s) < 3) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}

int dp[maxn][maxs], ndp[maxn][maxs];

void solve() {
  s = min(s, k * (n - k));
  for (int i = 0; i <= s; i++) {
    dp[0][i] = inf;
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i + 1; j++) {
      for (int t = 0; t <= s; t++) {
        ndp[j][t] = inf;
      }
    }
    for (int j = 0; j <= i; j++) {
      for (int t = 0; t <= s; t++) {
        auto cur = dp[j][t];
        if (cur >= inf) {
          continue;
        }
        ndp[j][t] = min(ndp[j][t], cur);
        int nt = t + (i - j);
        if (nt <= s) {
          ndp[j + 1][nt] = min(ndp[j + 1][nt], cur + a[i]);
        }
      }
    }
    swap(dp, ndp);
  }
  int res = inf;
  for (int t = 0; t <= s; t++) {
    res = min(res, dp[k][t]);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second

const int N=3e5+9,mod=20071027,inf=1e8;
int ar[152],dp[152][76][5630];
int n,k,s;

int minimize(int ind,int need,int rem)
{
    if(ind>n)
    {
        if(need==0)return 0;
        return inf;
    }
    if(need==0)return 0;

    if(~dp[ind][need][rem])return dp[ind][need][rem];

    int ret=ar[ind]+minimize(ind+1,need-1,rem);

    if(rem>=need)ret=min( ret , minimize(ind+1,need,rem-need));

    return dp[ind][need][rem]=ret;

}

int maximize(int ind,int need,int rem)
{

    if(ind>n)
    {
        if(need==0)return 0;
        return -inf;
    }
    if(need==0)return 0;

    if(~dp[ind][need][rem])return dp[ind][need][rem];

    int ret=ar[ind]+maximize(ind+1,need-1,rem);

    if(rem>=need)ret=max( ret , maximize(ind+1,need,rem-need));

    return dp[ind][need][rem]=ret;
}

int main()
{

    cin>>n>>k>>s;
    int  tt=0;
    memset(dp,-1,sizeof dp);
    for(int i=1;i<=n;i++)cin>>ar[i],tt+=ar[i];
    if(k<76)cout<<minimize(1,k,min(s,5627))<<"\n";
    else cout<<tt-maximize(1,n-k,min(s,5627))<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second

const int N=3e5+9,mod=20071027,inf=1e8;
int ar[152],dp[152][76][5630];
int n,k,s;

int minimize(int ind,int need,int rem)
{
    if(ind>n)
    {
        if(need==0)return 0;
        return inf;
    }
    if(need==0)return 0;

    if(~dp[ind][need][rem])return dp[ind][need][rem];

    int ret=ar[ind]+minimize(ind+1,need-1,rem);

    if(rem>=need)ret=min( ret , minimize(ind+1,need,rem-need));

    return dp[ind][need][rem]=ret;

}

int maximize(int ind,int need,int rem)
{

    if(ind==0)
    {
        if(need==0)return 0;
        return -inf;
    }
    if(need==0)return 0;

    if(~dp[ind][need][rem])return dp[ind][need][rem];

    int ret= ar[ind]+maximize (ind-1,need-1,rem);

    if(rem>=need)ret=max( ret ,maximize(ind-1,need,rem-need));

    return dp[ind][need][rem]=ret;
}

int main()
{

    cin>>n>>k>>s;
    int  tt=0;
    memset(dp,-1,sizeof dp);
    for(int i=1;i<=n;i++)cin>>ar[i],tt+=ar[i];
    if(k<76)cout<<minimize(1,k,min(s,5626))<<"\n";
    else cout<<tt-maximize(n,n-k,min(s,5626))<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second

const int N=3e5+9,mod=20071027,inf=1e8;
int ar[152],dp[152][76][5630];
int n,k,s;

int minimize(int ind,int need,int rem)
{
    if(ind>n)
    {
        if(need==0)return 0;
        return inf;
    }
    if(need==0)return 0;

    if(~dp[ind][need][rem])return dp[ind][need][rem];

    int ret=ar[ind]+minimize(ind+1,need-1,rem);

    if(rem>=need)ret=min( ret , minimize(ind+1,need,rem-need));

    return dp[ind][need][rem]=ret;

}

int maximize(int ind,int need,int rem)
{

    if(ind>n)
    {
        if(need==0)return 0;
        return -inf;
    }
    if(need==0)return 0;

    if(~dp[ind][need][rem])return dp[ind][need][rem];

    int ret=ar[ind]+minimize(ind+1,need-1,rem);

    if(rem>=need)ret=max( ret , minimize(ind+1,need,rem-need));

    return dp[ind][need][rem]=ret;
}

int main()
{

    cin>>n>>k>>s;
    int  tt=0;
    memset(dp,-1,sizeof dp);
    for(int i=1;i<=n;i++)cin>>ar[i],tt+=ar[i];
    if(k<76)cout<<minimize(1,k,min(s,5627))<<"\n";
    else cout<<tt-maximize(1,n-k,min(s,5627))<<"\n";
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 150
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,k,s,f[MN+5][MN*MN+5],a[MN+5];
inline void R(int&x,int y){y<x?x=y:0;}
int main()
{
	n=read();k=read();s=min(read(),k*(n-k)+5);
	memset(f,127,sizeof(f));f[0][s]=0;int ans=2e9;
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<=n;++i)
		for(int j=min(i,k)-1;~j;--j)
			for(int l=0;l<=s;++l)
				if(f[j][l]<2e9&&i-j-1<=l) R(f[j+1][l-(i-j-1)],f[j][l]+a[i]);
	for(int l=0;l<=s;++l) R(ans,f[k][l]);
	printf("%d\n",ans);
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

const int N = 155;
const int M = 12005;

int n, k, s, a[N], dp[N][M];

int main(){
      cin >> n >> k >> s;

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

      if(s >= (n + 1) * n / 2){
            sort(a + 1, a + n + 1);
            int sum = 0;
            for(int i = 1; i <= k; i ++)
                  sum += a[i];
            cout << sum << endl;
            return 0;
      }

      s += k * (k + 1) / 2;

      for(int i =0; i < N; i ++)
            for(int j = 0; j < M; j ++)
                  dp[i][j] = 1e9;

      dp[0][0] = 0;

      for(int i = 1; i <= n; i ++){
            for(int j = i; j >= 1; j --){
                  for(int k = s; k >= i; k --){
                        dp[j][k] = min(dp[j][k], dp[j - 1][k - i] + a[i]);
                  }
            }
      }

      int ans = 1e9;

      for(int i = 0; i <= s; i ++)
            ans = min(ans, dp[k][i]);

      cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long li;

const int maxn = 150, maxs = 5625;
const int inf = 0x3f3f3f3f;

int n, k, s, a[maxn];
int dp[2][maxn + 1][maxs + 1];

void Min(int &x, int y) { if (y < x) x = y; }

int main(void) {
  scanf("%d%d%d", &n, &k, &s);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  s = min(s, maxs);
  memset(dp, 0x3f, sizeof dp);
  dp[0][0][0] = 0;
  for (int i = 0; i < n; ++i) {
    memset(dp[1], 0x3f, sizeof dp[1]);
    for (int cnt = 0; cnt <= i; ++cnt) {
      for (int use = 0; use <= s; ++use) {
        Min(dp[1][cnt][use], dp[0][cnt][use]);
        if (use + i - cnt <= s) {
          Min(dp[1][cnt + 1][use + i - cnt], dp[0][cnt][use] + a[i]);
        }
      }
    }
    memcpy(dp[0], dp[1], sizeof dp[0]);
  }
  int ans = inf;
  for (int use = 0; use <= s; ++use) {
    Min(ans, dp[0][k][use]);
  }
  printf("%d\n", ans);
  return 0;
}


#include <iostream>
#include <cstring>

typedef long long ll;

const int ms = 150;
const int mi = 76 * 75 / 2 + 76 * 76 + 20;

int dp[ms][mi];

int main()
{
	memset(dp, 0x3f, sizeof dp);
	int n, kk, s;
	std::cin >> n >> kk >> s;
	s = std::min(s, mi - 1);
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++)
	{
		int cost;
		std::cin >> cost;
		for(int j = i; j > 0; j--)
		{
			for(int k = s; k >= i - j; k--)
			{
				dp[j][k] = std::min(dp[j][k], dp[j - 1][k - (i - j)] + cost);
			}
		}
	}
	int ans = 0x3f3f3f3f;
	for(int i = 0; i <= s; i++)
		ans = std::min(ans, dp[kk][i]);
	std::cout << ans << '\n';
}


#include <iostream>
#include <cstring>

typedef long long ll;

const int ms = 151;
const int mi = 76 * 75 / 2 + 76 * 76 + 20;

int dp[ms][mi];

int main()
{
	memset(dp, 0x3f, sizeof dp);
	int n, kk, s;
	std::cin >> n >> kk >> s;
	s = std::min(s, mi - 1);
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++)
	{
		int cost;
		std::cin >> cost;
		for(int j = i; j > 0; j--)
		{
			for(int k = s; k >= i - j; k--)
			{
				dp[j][k] = std::min(dp[j][k], dp[j - 1][k - (i - j)] + cost);
			}
		}
	}
	int ans = 0x3f3f3f3f;
	for(int i = 0; i <= s; i++)
		ans = std::min(ans, dp[kk][i]);
	std::cout << ans << '\n';
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,s,a[1000],t=0;
long long f[2][200][20000];
inline void update(long long &a,long long b){if(b>0&&(a<0||a>b))a=b;}
int main()
{
	scanf("%d%d%d",&n,&k,&s);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	if(s>k*(n-k))
	{
		sort(a+1,a+1+n);
		long long ans=0;
		for(int i=1;i<=k;i++)ans+=a[i];
		printf("%lld\n",ans);
		return 0;
	}
	memset(f,-1,sizeof f);
	f[0][0][0]=f[1][0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i&&j<=k;j++)
			for(int l=0;l<=i*(i-1)/2&&l<=s;l++)
			{
				update(f[t^1][j][l],f[t][j][l]);
				update(f[t^1][j+1][l+i-j],f[t][j][l]+a[i+1]);
				//if(f[t][j][l]>0)printf("F[%d][%d][%d]=%lld\n",i,j,l,f[t][j][l]);
				if(i==j)break;
			}
		t^=1;
	}
	long long ans=-1;
	for(int i=0;i<=n*(n-1)/2&&i<=s;i++)update(ans,f[t^1][k][i]);
	printf("%lld\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,s,a[1000],t=0;
long long f[2][200][20000];
inline void update(long long &a,long long b){if(b>0&&(a<0||a>b))a=b;}
int main()
{
	scanf("%d%d%d",&n,&k,&s);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	if(s>k*(n-k))
	{
		sort(a+1,a+1+n);
		long long ans=0;
		for(int i=1;i<=k;i++)ans+=a[i];
		printf("%lld\n",ans);
		return 0;
	}
	memset(f,-1,sizeof f);
	f[0][0][0]=f[1][0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i&&j<=k;j++)
			for(int l=0;l<=i*(i-1)/2;l++)
			{
				update(f[t^1][j][l],f[t][j][l]);
				update(f[t^1][j+1][l+i-j],f[t][j][l]+a[i+1]);
				//if(f[t][j][l]>0)printf("F[%d][%d][%d]=%lld\n",i,j,l,f[t][j][l]);
				if(i==j)break;
			}
		t^=1;
	}
	long long ans=-1;
	for(int i=0;i<=s;i++)update(ans,f[t^1][k][i]);
	printf("%lld\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,s,a[1000],t=0;
long long f[2][200][20000];
inline void update(long long &a,long long b){if(b>0&&(a<0||a>b))a=b;}
int main()
{
	scanf("%d%d%d",&n,&k,&s);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	if(s>=k*(n-k))
	{
		sort(a+1,a+1+n);
		long long ans=0;
		for(int i=1;i<=k;i++)ans+=a[i];
		printf("%lld\n",ans);
		return 0;
	}
	memset(f,-1,sizeof f);
	f[0][0][0]=f[1][0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i&&j<=k;j++)
			for(int l=0;l<=i*(i-1)/2&&l<=s;l++)
			{
				//printf("Updating f[%d][%d][%d]=%lld to f[%d][%d][%d]=%lld\n",t^1,j,l,f[t^1][j][l],t,j,l,f[t][j][l]);
				update(f[t^1][j][l],f[t][j][l]);
				if(f[t][j][l]!=-1)update(f[t^1][j+1][l+i-j],f[t][j][l]+a[i+1]);
				if(i==j)break;
			}
		t^=1;
	}
	long long ans=-1;
	for(int i=0;i<=n*(n-1)/2&&i<=s;i++)update(ans,f[t^1][k][i]);
	printf("%lld\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,s,a[1000],t=0;
long long f[2][200][20000];
inline void update(long long &a,long long b){if(b>0&&(a<0||a>b))a=b;}
int main()
{
	scanf("%d%d%d",&n,&k,&s);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	if(s>=k*(n-k))
	{
		sort(a+1,a+1+n);
		long long ans=0;
		for(int i=1;i<=k;i++)ans+=a[i];
		printf("%lld\n",ans);
		return 0;
	}
	memset(f,-1,sizeof f);
	f[0][0][0]=f[1][0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i&&j<=k;j++)
			for(int l=0;l<=i*(i-1)/2&&l<=s;l++)
			{
				update(f[t^1][j][l],f[t][j][l]);
				update(f[t^1][j+1][l+i-j],f[t][j][l]+a[i+1]);
				//if(f[t][j][l]>0)printf("F[%d][%d][%d]=%lld\n",i,j,l,f[t][j][l]);
				if(i==j)break;
			}
		t^=1;
	}
	long long ans=-1;
	for(int i=0;i<=n*(n-1)/2&&i<=s;i++)update(ans,f[t^1][k][i]);
	printf("%lld\n",ans);
	return 0;
}