/* * * File: stuff.cpp * Author: Andy Y.F. Huang (azneye) * Created on Aug 23, 2014, 11:50:25 PM */ #include <bits/stdc++.h> using namespace std; namespace stuff { typedef long long ll; const int MAX = 5000; ll dp[MAX + 111]; void solve(int test_num) { ll N; int A, B, C; cin >> N >> A >> B >> C; memset(dp, 0, sizeof(dp)); dp[0] = 1; for (int x = 1; x < MAX; ++x) { dp[x] = dp[x - 1]; if (x >= max(A, B)) { dp[x] = max(dp[x], dp[x - A] + dp[x - B]); } if (x >= max(A, C)) { dp[x] = max(dp[x], dp[x - A] + dp[x - C]); } if (x >= max(B, C)) { dp[x] = max(dp[x], dp[x - B] + dp[x - C]); } if (x >= max(A, max(B, C))) { dp[x] = max(dp[x], dp[x - A] + dp[x - B] + dp[x - C]); } } for (int c = 0;; ++c) { if (dp[c] >= N) { cout << c << endl; break; } } } void solve() { #ifdef AZN //make_case(); double start_t = clock(); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); //freopen("azn.txt", "w", stderr); #endif ios::sync_with_stdio(false); cin.tie(NULL); int T = 1; //scanf("%d", &T); cin >> T; for (int t = 1; t <= T; t++) solve(t); #ifdef AZN cerr << fixed << setprecision(3) << "Took: " << ((clock() - start_t) / CLOCKS_PER_SEC); #endif } } int main() { stuff::solve(); return 0; }