QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#15154. Fence

Statistics

Farmer John intends to build a fence to enclose his pasture, for which he needs lumber of specific dimensions. He goes to a lumberyard to purchase wood, but the owner says he only has a few large boards left. John can purchase these boards and cut them into the sizes he needs. John has a magical saw that allows him to cut boards without any loss of material; for example, a board of length 10 can be cut into two boards of lengths 8 and 2.

Your task is to determine the maximum number of boards John can obtain that meet his requirements, given the dimensions of the boards he needs and the dimensions of the boards available from the lumberyard.

Input

The first line contains an integer $m$ ($m \le 50$), representing the number of boards the lumberyard owner can provide. This is followed by $m$ lines, each representing the length of one of the boards provided by the owner. The next line (the $(m+2)$-th line) contains an integer $n$ ($n \le 1000$), representing the number of boards John needs. The following $n$ lines represent the length of each board he needs. All board dimensions are less than $32767$. (Each board provided by the owner and each board needed by John can only be used once.)

Output

A single line containing the maximum number of boards John can obtain that meet his requirements.

Examples

Input 1

4
30
40
50
25
10
15
16
17
18
19
20
21
25
24
30

Output 1

7

Note 1

Explanation: 25 cuts into 21 30 cuts into 20 40 cuts into 19, 18 50 cuts into 15, 16, 17

Input 2

3
20
10
10
9
3
3
3
5
5
7
8
8
9

Output 2

7

Note 2

Explanation: 20 cuts into 5, 7, 8 10 cuts into 5, 3 10 cuts into 3, 3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.