P25284 [AtCoder] Balls
普及
题目描述

Problem Description

There are $ N $ balls with integers written on them, and the integers on the balls are $ A_1 $, $ ... $, $ A_N $ respectively.

You can perform the following operations on these balls:

  • Collide two balls. When the integers on the balls are $ x $ and $ y $ respectively, these balls disappear and a new ball with the integer $x \times y$ appears.
  • Tap one ball while mentally focusing on an integer $ y $ (where $ y $ is at least 2). When the integer on the ball is $ x $ and the focused integer is $ y $, if $ x $ is divisible by $ y $, the tapped ball disappears and two new balls with integers $ y $ and $ x/y $ appear.

By performing these operations any number of times, determine if it is possible to create a state where there are $ M $ balls with the integers $ B_1 $, $ ... $, $ B_M $ written on them.

Input Format

The input is given from the standard input in the following format:

$ N $ $ A_1 $ $ ... $ $ A_N $ $ M $ $ B_1 $ $ ... $ $ B_M $

Output Format

Output Yes if it is possible to create a state where the integers on the balls are $ B_1 $, $ ... $, $ B_M $, otherwise output No.

Sample Input and Output

Sample Input #1

4
3 4 6 8
5
2 2 4 6 6

Sample Output #1

Yes

Sample Input #2

7
2 3 4 5 6 8 9
7
2 3 4 5 6 8 9

Sample Output #2

Yes

Sample Input #3

5
2 3 5 6 8
9
2 3 4 4 4 4 5 6 7

Sample Output #3

No

Notes/Hints

Constraints

  • $1 \leq N, M \leq 9$
  • $2 \leq A_i, B_i \leq 9$
  • $A_i \leq A_{i+1}$
  • $B_i \leq B_{i+1}$

Sample Explanation 1

For example, you can achieve this by performing the following operations:
- Tap the ball with $ 8 $ while focusing on $ 2 $ to create balls with $ 2 $ and $ 4 $. Now there are $ 5 $ balls with integers $ 2, 3, 4, 4, 6 $.
- Tap one of the balls with $ 4 $ while focusing on $ 2 $ to create two balls with $ 2 $. Now there are $ 6 $ balls with integers $ 2, 2, 2, 3, 4, 6 $.
- Collide the balls with $ 2 $ and $ 3 $. Now there are $ 5 $ balls with integers $ 2, 2, 4, 6, 6 $.

Sample Explanation 2

Note that no operations are needed if the initial state already matches the target state.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 3 4 6 8 5 2 2 4 6 6
样例输出
Yes