A - Exchange Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

日本では、1 円、5 円、10 円、50 円、100 円、500 円の 6 種類の硬貨が流通しています。これについて、次の問いに答えてください。

AtCoder さんの財布の中には、1 円硬貨 A 枚、5 円硬貨 B 枚、10 円硬貨 C 枚、50 円硬貨 D 枚、100 円硬貨 E 枚、500 円硬貨 F 枚が入っています。

AtCoder さんは、これから N 個の店で順番に買い物を行います。 具体的には、i 番目 (1 \leq i \leq N) に訪れる店では税込 X_i 円の商品を 1 つ購入する予定です。

釣銭の授受には時間がかかるので、彼は支払いに使う硬貨を上手く選ぶことで、すべての店でちょうどの金額を支払って商品を購入したいです。 このようなことが可能か、判定してください。

制約

  • 0 \leq A \leq 200
  • 0 \leq B \leq 200
  • 0 \leq C \leq 200
  • 0 \leq D \leq 200
  • 0 \leq E \leq 200
  • 0 \leq F \leq 200
  • 1 \leq N \leq 10
  • 1 \leq X_i \leq 10000 \ (1 \leq i \leq N)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられます。

A B C D E F
N
X_1 X_2 \cdots X_N

出力

可能ならば Yes、不可能ならば No と出力してください。


入力例 1

0 0 6 3 4 1
3
700 250 160

出力例 1

Yes

たとえば以下のように支払いを行うと、3 店舗すべてでちょうどの支払いを行うことができます。

  • 1 番目に訪れる店:100 円硬貨を 2 枚、500 円硬貨を 1 枚使う。
  • 2 番目に訪れる店:10 円硬貨を 5 枚、100 円硬貨を 2 枚使う。
  • 3 番目に訪れる店:10 円硬貨を 1 枚、50 円硬貨を 3 枚使う。

入力例 2

0 0 0 2 4 0
3
100 200 300

出力例 2

No

財布に入っている金額は 500 円ですが、合計 100+200+300=600 円の支払いを行う必要があるため、すべての商品を購入することができません。


入力例 3

0 0 0 0 8 8
1
250

出力例 3

No

財布に 50 円以下の硬貨が入っていないため、250 円ちょうどを支払うことはできません。


入力例 4

20 5 9 7 10 6
5
177 177 177 177 177

出力例 4

Yes

入力例 5

17 5 9 7 10 6
5
177 177 177 177 177

出力例 5

No

Score: 300 points

Problem Statement

In Japan, there are six types of coins in circulation: 1 yen, 5 yen, 10 yen, 50 yen, 100 yen, and 500 yen. Answer the following question regarding these coins.

Mr. AtCoder's wallet contains A 1-yen coins, B 5-yen coins, C 10-yen coins, D 50-yen coins, E 100-yen coins, and F 500-yen coins.

He is planning to shop at N stores in sequence. Specifically, at the i-th store (1 \leq i \leq N), he plans to buy one item that costs X_i yen (including tax).

Giving and receiving change takes time, so he wants to choose his coins so that he can pay the exact amount at each store. Determine if this is possible.

Constraints

  • 0 \leq A \leq 200
  • 0 \leq B \leq 200
  • 0 \leq C \leq 200
  • 0 \leq D \leq 200
  • 0 \leq E \leq 200
  • 0 \leq F \leq 200
  • 1 \leq N \leq 10
  • 1 \leq X_i \leq 10000 \ (1 \leq i \leq N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

A B C D E F
N
X_1 X_2 \cdots X_N

Output

Print Yes if the objective is achievable, and No otherwise.


Sample Input 1

0 0 6 3 4 1
3
700 250 160

Sample Output 1

Yes

For example, he can make exact payments at all three stores as follows:

  • At the first store: Use two 100-yen coins and one 500-yen coin.
  • At the second store: Use five 10-yen coins and two 100-yen coins.
  • At the third store: Use one 10-yen coin and three 50-yen coins.

Sample Input 2

0 0 0 2 4 0
3
100 200 300

Sample Output 2

No

The total amount in the wallet is 500 yen, but a total payment of 100+200+300=600 yen is required, so it is impossible to purchase all the items.


Sample Input 3

0 0 0 0 8 8
1
250

Sample Output 3

No

There are no 50-yen or smaller coins in the wallet, so it is impossible to pay exactly 250 yen.


Sample Input 4

20 5 9 7 10 6
5
177 177 177 177 177

Sample Output 4

Yes

Sample Input 5

17 5 9 7 10 6
5
177 177 177 177 177

Sample Output 5

No