{"problem":{"name":"D. Vasya And The Matrix","description":{"content":"Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed! Vasya knows that the matrix consists of _n_ rows and _m_ col","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF1016D"},"statements":[{"statement_type":"Markdown","content":"Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed!\n\nVasya knows that the matrix consists of _n_ rows and _m_ columns. For each row, he knows the xor (bitwise excluding or) of the elements in this row. The sequence _a_1, _a_2, ..., _a__n_ denotes the xor of elements in rows with indices 1, 2, ..., _n_, respectively. Similarly, for each column, he knows the xor of the elements in this column. The sequence _b_1, _b_2, ..., _b__m_ denotes the xor of elements in columns with indices 1, 2, ..., _m_, respectively.\n\nHelp Vasya! Find a matrix satisfying the given constraints or tell him that there is no suitable matrix.\n\n## Input\n\nThe first line contains two numbers _n_ and _m_ (2 ≤ _n_, _m_ ≤ 100) — the dimensions of the matrix.\n\nThe second line contains _n_ numbers _a_1, _a_2, ..., _a__n_ (0 ≤ _a__i_ ≤ 109), where _a__i_ is the xor of all elements in row _i_.\n\nThe third line contains _m_ numbers _b_1, _b_2, ..., _b__m_ (0 ≤ _b__i_ ≤ 109), where _b__i_ is the xor of all elements in column _i_.\n\n## Output\n\nIf there is no matrix satisfying the given constraints in the first line, output \"NO\".\n\nOtherwise, on the first line output \"YES\", and then _n_ rows of _m_ numbers in each _c__i_1, _c__i_2, ... , _c__im_ (0 ≤ _c__ij_ ≤ 2·109) — the description of the matrix.\n\nIf there are several suitable matrices, it is allowed to print any of them.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"现在 Vasya 正在参加一场数学考试。为了取得好成绩，Vasya 需要猜出老师构造的矩阵！\n\nVasya 知道该矩阵由 #cf_span[n] 行和 #cf_span[m] 列组成。对于每一行，他知道该行元素的异或（按位异或）。序列 #cf_span[a1, a2, ..., an] 表示索引为 #cf_span[1], #cf_span[2], ..., #cf_span[n] 的行中元素的异或。类似地，对于每一列，他知道该列元素的异或。序列 #cf_span[b1, b2, ..., bm] 表示索引为 #cf_span[1], #cf_span[2], ..., #cf_span[m] 的列中元素的异或。\n\n帮助 Vasya！找出满足给定约束的矩阵，或告诉他不存在合适的矩阵。\n\n第一行包含两个数 #cf_span[n] 和 #cf_span[m (2 ≤ n, m ≤ 100)] —— 矩阵的维度。\n\n第二行包含 #cf_span[n] 个数 #cf_span[a1, a2, ..., an (0 ≤ ai ≤ 10^9)]，其中 #cf_span[ai] 是第 #cf_span[i] 行所有元素的异或。\n\n第三行包含 #cf_span[m] 个数 #cf_span[b1, b2, ..., bm (0 ≤ bi ≤ 10^9)]，其中 #cf_span[bi] 是第 #cf_span[i] 列所有元素的异或。\n\n如果不存在满足给定约束的矩阵，则在第一行输出 \"NO\"。\n\n否则，在第一行输出 \"YES\"，然后输出 #cf_span[n] 行，每行包含 #cf_span[m] 个数 #cf_span[ci1, ci2, ... , cim (0 ≤ cij ≤ 2·10^9)] —— 矩阵的描述。\n\n如果存在多个符合条件的矩阵，允许输出其中任意一个。\n\n## Input\n\n第一行包含两个数 #cf_span[n] 和 #cf_span[m (2 ≤ n, m ≤ 100)] —— 矩阵的维度。第二行包含 #cf_span[n] 个数 #cf_span[a1, a2, ..., an (0 ≤ ai ≤ 10^9)]，其中 #cf_span[ai] 是第 #cf_span[i] 行所有元素的异或。第三行包含 #cf_span[m] 个数 #cf_span[b1, b2, ..., bm (0 ≤ bi ≤ 10^9)]，其中 #cf_span[bi] 是第 #cf_span[i] 列所有元素的异或。\n\n## Output\n\n如果不存在满足给定约束的矩阵，则在第一行输出 \"NO\"。否则，在第一行输出 \"YES\"，然后输出 #cf_span[n] 行，每行包含 #cf_span[m] 个数 #cf_span[ci1, ci2, ... , cim (0 ≤ cij ≤ 2·10^9)] —— 矩阵的描述。如果存在多个符合条件的矩阵，允许输出其中任意一个。\n\n[samples]","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n, m \\in \\mathbb{Z} $ be the dimensions of the matrix, with $ 2 \\leq n, m \\leq 100 $.  \nLet $ A = (a_1, a_2, \\dots, a_n) \\in \\mathbb{Z}_{\\geq 0}^n $ be the row XOR constraints.  \nLet $ B = (b_1, b_2, \\dots, b_m) \\in \\mathbb{Z}_{\\geq 0}^m $ be the column XOR constraints.  \nLet $ C = (c_{ij}) \\in \\mathbb{Z}_{\\geq 0}^{n \\times m} $ be the matrix to be constructed, with $ 0 \\leq c_{ij} \\leq 2 \\cdot 10^9 $.\n\n**Constraints**  \n1. For each row $ i \\in \\{1, \\dots, n\\} $:  \n   $$\n   \\bigoplus_{j=1}^{m} c_{ij} = a_i\n   $$  \n2. For each column $ j \\in \\{1, \\dots, m\\} $:  \n   $$\n   \\bigoplus_{i=1}^{n} c_{ij} = b_j\n   $$  \n3. The total XOR of all elements computed via rows must equal that via columns:  \n   $$\n   \\bigoplus_{i=1}^{n} a_i = \\bigoplus_{j=1}^{m} b_j\n   $$\n\n**Objective**  \nDetermine whether there exists a matrix $ C $ satisfying the above constraints. If yes, output any such matrix; otherwise, output \"NO\".","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF1016D","tags":["constructive algorithms","flows","math"],"sample_group":[["2 3\n2 9\n5 3 13","YES\n3 4 5\n6 7 8"],["3 3\n1 7 6\n2 15 12","NO"]],"created_at":"2026-03-03 11:00:39"}}