Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Hablu Is in Quarantine

By SrijonKumar · Limits 500ms, 512 MB

The soldiers are being trained to fight against the Coronavirus. Mr. Hablu will shake hands with some soldiers there. So all the soldiers were placed on an n×nn \times n size grid. After talking to them, Mr. Hablu decided to shake hands with XX soldiers. But sadly, some of those soldiers may have the Coronavirus in their body, so that virus can infect Mr. Hablu and even those with whom he shakes hands afterwards.

You will be given a 2D grid of size n×nn \times n where healthy soldiers will be marked by aa and infected soldiers will be marked by cc. In the next line you will be given a positive integer XX which will indicate the total number of soldiers and at the last line will contain ID numbers of the soldier with whom Mr. Hablu will shake hands.

Input

In the first line of input you will be given an integer n(1n500)n \Big(1 \leq n \leq 500 \Big) and in the next line the input will contain a grid of size n×nn \times n.

Then you will be given an integer X(1Xn2)X \Big(1 \leq X \leq n^2 \Big) and the next line will contain XX positive integers.

Output

If Mr.Hablu is will get infected then you need to print “YES” otherwise print “NO”.

If the output is “YES” then in the next line you need to print the ID numbers of the soldiers who will get infected by shaking hands with Mr. Hablu.

Samples

InputOutput
5
aaaaa
accaa
acaaa
accaa
acaac
5
1 2 6 13 16
NO
InputOutput
5
aaaaa
accaa
acaaa
accaa
acaac
5
1 5 7 4 19
YES
4 19

Discussion

Statistics


78% Solution Ratio

EgorKulikovEarliest, Apr '20

theunownFastest, 0.0s

agtxdyLightest, 131 kB

shantolShortest, 194B

Submit

Login to submit

Related Contests

Toph uses cookies. By continuing you agree to our Cookie Policy.