#include <iostream>
#include <algorithm>
using namespace std;
const int num = 4;
int times[num] = { 1, 2, 5, 10 };
int dp[2][num];
int solve(int dir, int n)
{
if (0 < dp[dir][n]) return dp[dir][n];
if (n < 2) return times[!dir && n];
dp[dir][n] = 99999;
if (dir)
{
if (2 < n) dp[dir][n] = min(dp[dir][n], solve(0, n - 2) + times[1] + times[n]);
dp[dir][n] = min(dp[dir][n], solve(1, n - 1) + times[0] + times[n]);
}
else
dp[dir][n] = min(dp[dir][n], solve(1, n) + times[0] + times[1]);
return dp[dir][n];
}
int main()
{
sort(times, times + num);
cout << solve(0, num - 1) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IG51bSA9IDQ7CmludCB0aW1lc1tudW1dID0geyAxLCAyLCA1LCAxMCB9OwppbnQgZHBbMl1bbnVtXTsKCmludCBzb2x2ZShpbnQgZGlyLCBpbnQgbikKewoJaWYgKDAgPCBkcFtkaXJdW25dKSByZXR1cm4gZHBbZGlyXVtuXTsKCWlmIChuIDwgMikgcmV0dXJuIHRpbWVzWyFkaXIgJiYgbl07CgoJZHBbZGlyXVtuXSA9IDk5OTk5OwoJaWYgKGRpcikKCXsKCQlpZiAoMiA8IG4pIGRwW2Rpcl1bbl0gPSBtaW4oZHBbZGlyXVtuXSwgc29sdmUoMCwgbiAtIDIpICsgdGltZXNbMV0gKyB0aW1lc1tuXSk7CgkJZHBbZGlyXVtuXSA9IG1pbihkcFtkaXJdW25dLCBzb2x2ZSgxLCBuIC0gMSkgKyB0aW1lc1swXSArIHRpbWVzW25dKTsKCX0KCWVsc2UKCQlkcFtkaXJdW25dID0gbWluKGRwW2Rpcl1bbl0sIHNvbHZlKDEsIG4pICsgdGltZXNbMF0gKyB0aW1lc1sxXSk7CgoJcmV0dXJuIGRwW2Rpcl1bbl07Cn0KCmludCBtYWluKCkKewoJc29ydCh0aW1lcywgdGltZXMgKyBudW0pOwoJY291dCA8PCBzb2x2ZSgwLCBudW0gLSAxKSA8PCBlbmRsOwoKCXJldHVybiAwOwp9Cg==