import std; void main () { int N = readln.chomp.to!int; int A, B, C; readln.read(A, B, C); solve(N, A, B, C); } void solve (int N, int A, int B, int C) { // dp[i] := i枚のうどん券で得られる最大割引 int[] dp = new int[](N+1); // initialize dp[] = -1; dp[0] = 0; auto comsumption = [3, 5, 10]; auto discount = [A, B, C]; foreach (i; 1..N+1) { foreach (j; 0..cast(int) comsumption.length) { if (0 <= i-comsumption[j] && dp[ i-comsumption[j] ] != -1) { dp[i] = max(dp[i], dp[ i-comsumption[j] ] + discount[j]); } } } long ans = 0; foreach (price; dp) { ans = max(ans, price); } writeln(ans); } void read(T...)(string S, ref T args) { auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }