#arc177a. A - Exchange

A - Exchange

Score: 300300 points

问题陈述

在日本,流通着六种硬币:1日元、5日元、10日元、50日元、100日元和500日元。请回答有关这些硬币的以下问题。

AtCoder 先生的钱包里有A枚1日元硬币、B枚5日元硬币、C枚10日元硬币、D枚50日元硬币、E枚100日元硬币和F枚500日元硬币。

他计划依次去N家商店购物。具体来说,在第 ii 家商店 1iN(1 ≤ i ≤ N),他打算购买一件含税价格为 XiX_i 日元的商品。

找零需要时间,所以他想选择硬币,以便在每家商店都能支付正好的金额。确定这是否可能。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

In Japan, there are six types of coins in circulation: 11 yen, 55 yen, 1010 yen, 5050 yen, 100100 yen, and 500500 yen. Answer the following question regarding these coins.

Mr. AtCoder's wallet contains AA 11-yen coins, BB 55-yen coins, CC 1010-yen coins, DD 5050-yen coins, EE 100100-yen coins, and FF 500500-yen coins.

He is planning to shop at NN stores in sequence. Specifically, at the ii-th store (1iN)(1 \leq i \leq N), he plans to buy one item that costs XiX_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

  • 0A2000 \leq A \leq 200
  • 0B2000 \leq B \leq 200
  • 0C2000 \leq C \leq 200
  • 0D2000 \leq D \leq 200
  • 0E2000 \leq E \leq 200
  • 0F2000 \leq F \leq 200
  • 1N101 \leq N \leq 10
  • 1Xi10000 (1iN)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:

AA BB CC DD EE FF

NN

X1X_1 X2X_2 \cdots XNX_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 100100-yen coins and one 500500-yen coin.
  • At the second store: Use five 1010-yen coins and two 100100-yen coins.
  • At the third store: Use one 1010-yen coin and three 5050-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 500500 yen, but a total payment of 100+200+300=600100+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 5050-yen or smaller coins in the wallet, so it is impossible to pay exactly 250250 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