Under construction

Still being built. Things may change

Sinchon Regional Middle and High School Student Programming Contest Club Joint Competition

Time limit1sMemory limit1024 MB

Summary
Fill the empty seats with ages 8 to 19 so every AND or OR constraint between two seats holds, or report that no arrangement exists.
Level

Medium7 of 10

Topics
Bit manipulation, Graph, Implementation
Solved
No attempts yet

Problem

Following the success of SUAPC, Yeondu is planning the "Sinchon Regional Middle and High School Student Programming Contest Club Joint Competition". Any student aged 88 to 1919 who attends an elementary, middle, or high school in Sinchon can take part.

Yeondu firmly believes in his own feng shui and Four Pillars theories, which are based on computer science. He thinks the seating arrangement by age is critical to a successful contest. The data he built from his Yin-Yang Bitron theory states, for the seats at positions xx and yy, the value the bitwise AND or bitwise OR of the two participants' ages must produce.

Kakao, which joined SUAPC 2021 Winter and is also a sponsor of this contest, asked for a favor. They want specific ages seated at a few chosen seats. Yeondu does not want to refuse the sponsor. He wants to know whether the remaining empty seats can be filled with suitable ages so that all of his data is satisfied. He already has many students aged 88 to 1919. Arrange the seats for him while he is busy preparing the contest.

Input

The input is given in the following format.

NN

a1,a2,…,aNa_1, a_2, \dots, a_N

MM

t1 x1 y1 z1t_1\ x_1\ y_1\ z_1

…\dots

tM xM yM zMt_M\ x_M\ y_M\ z_M

Output

If you can fill the empty seats with participants aged 88 to 1919 so that all of Yeondu's data is satisfied, print 11 on the first line. On the next line, print the ages of the participants seated at seat 11, seat 22, …\dots, seat NN, separated by spaces. If several arrangements are valid, print any one of them.

If no such arrangement exists, print 00 on the first line.

Constraints

  • NN is the number of seats. (2≤N≤500002 \le N \le 50000)

  • ai=0a_i = 0 or 8≤ai≤198 \le a_i \le 19

    • If ai=0a_i = 0, seat ii is empty.
    • If 8≤ai≤198 \le a_i \le 19, the participant seated at seat ii is aia_i years old.
  • MM is the number of data items. (1≤M≤1000001 \le M \le 100000)

  • tit_i is & or |.

    • If tit_i is &, the bitwise AND of the ages of the participants at seats xix_i and yiy_i must be ziz_i.
    • If tit_i is |, the bitwise OR of the ages of the participants at seats xix_i and yiy_i must be ziz_i.
  • 1≤xi,yi≤N1 \le x_i, y_i \le N, xi≠yix_i \ne y_i

  • 0≤zi≤310 \le z_i \le 31

  • All numbers in the input are integers.

Examples2

  1. Example 1

    Input
    4
    15 0 0 0
    3
    & 1 2 1
    & 1 3 12
    | 3 4 31
    
    Expected output
    1
    15 17 12 19
    
  2. Example 2

    Input
    3
    0 0 0
    3
    | 1 2 24
    | 2 3 24
    | 3 1 24
    
    Expected output
    0