{"problem":{"name":"Addition and Multiplication 2","description":{"content":"Takahashi has an integer $x$. Initially, $x=0$. Takahashi may do the following operation any number of times. *   Choose an integer $i\\ (1\\leq i \\leq 9)$. Pay $C_i$ yen (the currency in Japan) to rep","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc257_e"},"statements":[{"statement_type":"Markdown","content":"Takahashi has an integer $x$. Initially, $x=0$.\nTakahashi may do the following operation any number of times.\n\n*   Choose an integer $i\\ (1\\leq i \\leq 9)$. Pay $C_i$ yen (the currency in Japan) to replace $x$ with $10x + i$.\n\nTakahashi has a budget of $N$ yen. Find the maximum possible value of the final $x$ resulting from operations without exceeding the budget.\n\n## Constraints\n\n*   $1 \\leq N \\leq 10^6$\n*   $1 \\leq C_i \\leq N$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$C_1$ $C_2$ $\\ldots$ $C_9$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc257_e","tags":[],"sample_group":[["5\n5 4 3 3 2 5 3 5 3","95\n\nFor example, the operations where $i = 9$ and $i=5$ in this order change $x$ as:\n$0 \\rightarrow 9 \\rightarrow 95$.\nThe amount of money required for these operations is $C_9 + C_5 = 3 + 2 = 5$ yen, which does not exceed the budget. Since we can prove that we cannot make an integer greater than or equal to $96$ without exceeding the budget, the answer is $95$."],["20\n1 1 1 1 1 1 1 1 1","99999999999999999999\n\nNote that the answer may not fit into a $64$\\-bit integer type."]],"created_at":"2026-03-03 11:01:14"}}