PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000199. Sơn số lên hàng rào (Color the Fence)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sơn số lên hàng rào (Color the Fence)

Color the Fence

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Igor wants to paint the largest possible positive integer on a fence. He has vv liters of paint. Painting a digit dd from 11 to 99 requires exactly ada_d liters; digit 0 is forbidden.

He may write any sequence of allowed digits as long as the total amount of paint used does not exceed vv. Digits may repeat, and each occurrence incurs its own cost.

Find the numerically largest integer he can write. A number with more digits is always larger; at equal lengths, the earlier larger digit wins. Print -1 if no digit is affordable.

Input

  • The first line contains an integer vv, the paint budget.
  • The second line contains exactly nine positive integers a1,a2,…,a9a_1,a_2,\ldots,a_9, where ada_d is the cost of painting digit dd once.

Output

If at least one digit is affordable, print a single line containing the decimal digits of the largest possible integer without spaces or 0. Otherwise print exactly -1.

Subtasks

  • Subtask 1 (20 points): 0≤v≤200\le v\le 20; 1≤ad≤1051\le a_d\le10^5 for every 1≤d≤91\le d\le9.
  • Subtask 2 (30 points): 0≤v≤20000\le v\le 2000; 1≤ad≤1051\le a_d\le10^5 for every 1≤d≤91\le d\le9.
  • Subtask 3 (50 points): 0≤v≤1060\le v\le10^6; 1≤ad≤1051\le a_d\le10^5 for every 1≤d≤91\le d\le9.

Examples

Input

5
5 4 3 2 1 2 3 4 5

Output

55555

Explanation

The budget is v=5v=5. Digit 5 costs a5=1a_5=1, so five copies produce 55555. Since every digit costs at least 11, a six-digit number is impossible. At length five, each digit must cost 11; digit 5 is the largest affordable choice at that cost. Thus 55555 is optimal.