#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; long long m; cin >> n >> m; vector a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } vector b = a; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ b.emplace_back(a[i] + a[j]); } } sort(b.begin(), b.end()); long long ans = 0; for(auto x : b){ if(x > m) continue; ans = max(ans, x); auto iter = upper_bound(b.begin(), b.end(), m - x); if(iter == b.begin()) continue; iter--; ans = max(ans, x + *iter); } cout << ans << endl; }