Codeforces Round 270
F
Design Tutorial: Change the Goal
Codeforces
2700
原题
← EG →
翻译中…

There are some tasks which have the following structure: you are given a model, and you can do some operations, you should use these operations to achive the goal. One way to create a new task is to use the same model and same operations, but change the goal.

翻译中…

Let's have a try. I have created the following task for Topcoder SRM 557 Div1-Hard: you are given $*n*$ integers $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$. You are allowed to perform the assignments (as many as you want) of the following form $*x*_{*i*}$ ^= $*x*_{*j*}$ (in the original task $*i*$ and $*j*$ must be different, but in this task we allow $*i*$ to equal $*j*$). The goal is to maximize the sum of all $*x*_{*i*}$.

翻译中…

Now we just change the goal. You are also given $*n*$ integers $*y*_{1}, *y*_{2}, ..., *y*_{*n*}$. You should make $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$ exactly equal to $*y*_{1}, *y*_{2}, ..., *y*_{*n*}$. In other words, for each $*i*$ number $*x*_{*i*}$ should be equal to $*y*_{*i*}$.

翻译中…

Input

翻译中…

The first line contains an integer $*n*$ $(1 ≤ *n* ≤ 10000)$. The second line contains $*n*$ integers: $*x*_{1}$ to $*x*_{*n*}$ $(0 ≤ *x*_{*i*} ≤ 10^{9})$. The third line contains $*n*$ integers: $*y*_{1}$ to $*y*_{*n*}$ $(0 ≤ *y*_{*i*} ≤ 10^{9})$.

翻译中…

Output

翻译中…

If there is no solution, output -1.

翻译中…

If there is a solution, then in the first line output an integer $*m*$ $(0 ≤ *m* ≤ 1000000)$ – the number of assignments you need to perform. Then print $*m*$ lines, each line should contain two integers $*i*$ and $*j*$ $(1 ≤ *i*, *j* ≤ *n*)$, which denote assignment $*x*_{*i*}$ ^= $*x*_{*j*}$.

翻译中…

If there are multiple solutions you can print any of them. We can prove that under these constraints if there exists a solution then there always exists a solution with no more than $10^{6}$ operations.

翻译中…

Note

翻译中…

Assignment $*a*$ ^= $*b*$ denotes assignment $*a*$ = $*a*$ ^ $*b*$, where operation "^" is bitwise XOR of two integers.

翻译中…

样例

Input #1
2
3 5
6 0
Output #1
2
1 2
2 2
InputCopy OutputCopy
Input #2
5
0 0 0 0 0
1 2 3 4 5
Output #2
-1
InputCopy OutputCopy
Input #3
3
4 5 6
1 2 3
Output #3
5
3 1
1 2
2 2
2 3
3 1
InputCopy OutputCopy
Input #4
3
1 2 3
4 5 6
Output #4
-1
InputCopy OutputCopy
题目信息
题号
472F
时间限制
2 s
内存限制
256 MB
标签
构造
数学
矩阵

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。