#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) #define INF (1LL << 60) #define all(v) (v).begin(), (v).end() template void chmin(T &a, T b) { if (a > b) a = b; } template void chmax(T &a, T b) { if (a < b) a = b; } template struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt(t); return (is); } static int get_mod() { return mod; } }; using mint = ModInt<1000000007>; int main() { ll N, M, K; cin >> N >> M >> K; vector A(N); rep(i, N) { cin >> A[i]; } vector> s(3); ll ans = 0; rep(i, N) { s[0].push_back(A[i]); if (K >= 1 && A[i] <= M) chmax(ans, A[i]); rep(j, N) { s[1].push_back(A[i] + A[j]); rep(k, N) { s[2].push_back(A[i] + A[j] + A[k]); } } } rep(i, 3) { sort(all(s[i])); } rep(i, 3) { rep(j, 3) { if (i + j + 2 > K) continue; rep(k, s[i].size()) { ll goal = M - s[i][k] + 1; auto itr = lower_bound(all(s[j]), goal); if (itr == s[j].begin()) continue; itr--; chmax(ans, s[i][k] + *itr); } } } cout << ans << endl; }