405051: GYM101755 D Transfer Window

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Transfer Windowtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You play a football manager. There are n football players in the game, and k of them — a1, a2, ..., ak — are currently playing in your team. You want players b1, b2, ..., bk to play in your team. To achieve that, you can suggest other teams to exchange one of your players to their player.

For each ordered pair of distinct players (x, y) it is known whether or not a team controlled by AI would accept to exchange your player x to their player y. Determine whether it is possible to collect a team consisting of football players b1, b2, ..., bk and if it is, output the order of exchanges to achieve it.

Input

The first line contains two integers n and k (1 ≤ n ≤ 300, 1 ≤ k ≤ n) — the total number of football players in the game and the number of football players in your team.

The second line contains k distinct integers ai (1 ≤ ai ≤ n) — the players currently playing in your team.

The third line contains k distinct integers bi (1 ≤ bi ≤ n) — the players you want to see in your team.

Each of the next n lines contains n characters. Character in i-th line and j-th column equals «1», if the team controlled by AI would accept to exchange your player i to their player j, and «0», if it wouldn't. Characters on the main diagonal are equal to zero.

Output

In the first line output «YES», if it's possible to make a team of players b1, b2,  ..., bk, and «NO», if it's not.

In the case of the «YES» answer, in the second line output a single integer q (0 ≤ q ≤ n·n) — the number of exchanges, and then q lines — the sequence of exchanges. Each of these q lines must contain two distinct integers xj and yj (1 ≤ xj ≤ n, 1 ≤ yj ≤ n) — the number of player from your team you want to exchange and the number of player from another team you want to get for him. Please note that after j-th exchange player yj becomes a player of your team and player xj leaves your team.

If there are several sequences of exchanges leading to the desired result, output any of them. Also note that it's not required to minimize the number of exchanges, it's just enough if it doesn't exceed n·n.

ExamplesInput
5 2
1 2
4 5
00100
00100
00011
00000
00000
Output
YES
4
1 3
3 4
2 3
3 5
Input
3 2
1 2
2 3
000
001
010
Output
NO

加入题单

上一题 下一题 算法标签: