#include <bits/stdc++.h>
using namespace std;
long long solve(int a, int A, int b, int B, int n){
//ax + by <= n
//Ax + By -> max
//we know that there is optimal answer, where
//x < b or y < a
long long ans = 0;
for(int x = 0; a * x <= n && x < b; ++x){
int y = (n - a * x) / b;
ans = max(ans, A * (long long) x + B * (long long) y);
}
for(int y = 0; b * y <= n && y < a; ++y){
int x = (n - b * y) / a;
ans = max(ans, A * (long long) x + B * (long long) y);
}
return ans;
}
long long solve(int a, int A, int b, int B, int c, int C, int n){
//ax + by + cz <= n
//Ax + By + Cz -> max
//we know that there is optimal answer, where
//x, y or z < a * b * c
long long ans = 0;
for(int x = 0; a * x <= n && x < a * b * c; ++x){
ans = max(ans, A * (long long) x + solve(b, B, c, C, n - a * x));
}
for(int y = 0; b * y <= n && y < a * b * c; ++y){
ans = max(ans, B * (long long) y + solve(a, A, c, C, n - b * y));
}
for(int z = 0; c * z <= n && z < a * b * c; ++z){
ans = max(ans, C * (long long) z + solve(a, A, b, B, n - c * z));
}
return ans;
}
int main()
{
int b, d, m, n; cin >> b >> d >> m >> n;
if (b < d){
swap(b, d);
}
long long ans = solve(6, b, 9, b + d, n);//without Maksym
if (n >= 6){
ans = max(ans, m + solve(6, b, 9, b + d, 5, m, n - 6));//with Maksym
}
cout << ans << endl;
return 0;
}