As you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using lots of different types of brackets since prehistoric times. A bracket type is a positive integer. The shamans define a correct bracket sequence as follows:
For example, sequences {1, 1, - 1, 2, - 2, - 1} and {3, - 3} are correct bracket sequences, and {2, - 3} is not.
Moreover, after Vova became a shaman, he learned the most important correct bracket sequence {x_1, _x_2, …, _x__n}, consisting of n integers. As sequence x is the most important, Vova decided to encrypt it just in case.
Encrypting consists of two sequences. The first sequence {p_1, _p_2, …, _p__n} contains types of brackets, that is, p__i = |x__i| (1 ≤ i ≤ n). The second sequence {q_1, _q_2, …, _q__t} contains t integers — some positions (possibly, not all of them), which had negative numbers in sequence {x_1, _x_2, …, _x__n}.
Unfortunately, Vova forgot the main sequence. But he was lucky enough to keep the encryption: sequences {p_1, _p_2, …, _p__n} and {q_1, _q_2, …, _q__t}. Help Vova restore sequence x by the encryption. If there are multiple sequences that correspond to the encryption, restore any of them. If there are no such sequences, you should tell so.
Input
The first line of the input contains integer n (1 ≤ n ≤ 106). The second line contains n integers: p_1, _p_2, …, _p__n (1 ≤ p__i ≤ 109).
The third line contains integer t (0 ≤ t ≤ n), followed by t distinct integers q_1, _q_2, …, _q__t (1 ≤ q__i ≤ n).
The numbers in each line are separated by spaces.
Output
Print a single string "NO" (without the quotes) if Vova is mistaken and a suitable sequence {x_1, _x_2, …, _x__n} doesn't exist.
Otherwise, in the first line print "YES" (without the quotes) and in the second line print n integers x_1, _x_2, …, _x__n (|x__i| = p__i; x__q__j < 0). If there are multiple sequences that correspond to the encrypting, you are allowed to print any of them.
Examples
Input
2
1 1
0
Output
YES
1 -1
Input
4
1 1 1 1
1 3
Output
YES
1 1 -1 -1
Input
3
1 1 1
0
Output
NO
Input
4
1 2 2 1
2 3 4
Output
YES
1 2 -2 -1
题意是有1e9种括号,每种括号的左括号用k表示,右括号用-k表示,现在给出个序列,其中已知一些括号是右括号,可以再把一些左括号变右括号(正数取反)要找到一种括号匹配的方式
从后往前找,维护一个栈,如果当前的括号跟栈顶的匹配就马上匹配,否则改负号扔进栈里去。
如果当前这个括号跟栈顶的匹配,而你又选择不匹配的话,那么这个括号和栈顶都要分别再和后面的某个相同的括号匹配。
如果再后面的括号也真的存在,那么完全可以当前的和栈顶匹配,后面的自己匹配,所以当前和栈顶匹配这里也是可行的。如果后面的不存在,这样无解,只能当前的和栈顶匹配。所以当前的跟栈顶的能匹配就匹配。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
cf 287E
手机扫一扫
移动阅读更方便
你可能感兴趣的文章