Discription

Anton goes to school, his favorite lessons are arraystudying. He usually solves all the tasks pretty fast, but this time the teacher gave him a complicated one: given two arrays b and c of length n, find array a, such that:

where a and b means bitwise AND, while a or b means bitwise OR.

Usually Anton is good in arraystudying, but this problem is too hard, so Anton asks you to help.

Input

The first line of the input contains a single integers n (1 ≤ n ≤ 200 000) — the size of arrays b and c.

The second line contains n integers bi (0 ≤ bi ≤ 109) — elements of the array b.

Third line contains n integers ci (0 ≤ ci ≤ 109) — elements of the array c.

Output

If there is no solution, print  - 1.

Otherwise, the only line of the output should contain n non-negative integers ai — elements of the array a. If there are multiple possible solutions, you may print any of them.

Example

Input
4
6 8 4 4
16 22 10 10
Output
3 5 1 1 
Input
5
8 25 14 7 16
19 6 9 4 25
Output
-1

有一个显然的性质就是 (a&b)+(a|b)=a+b。
这个考虑每一位的贡献就行了。
于是我们可以得到c[i]+b[i]=a[i]*n+∑a[],从而可以开开心心的算出每一个a,然后带回去验证一下就可以了
/*
We know that b[i]+c[i]=n*a[i]+∑a[]
*/
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
using namespace std;
int b[maxn],c[maxn];
int a[maxn],n,m,ci[60];
ll tot=0,now;
int main(){
ci[0]=1;
for(int i=1;i<=30;i++) ci[i]=ci[i-1]<<1; scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",b+i),tot+=(ll)b[i];
for(int i=1;i<=n;i++) scanf("%d",c+i),tot+=(ll)c[i];
//tot is used to calculate the sum of array a[]
if(tot%(n<<1)){
puts("-1");
return 0;
} tot/=(n<<1); for(int i=1;i<=n;i++){
now=c[i]+b[i]-tot;
if(now%n){
puts("-1");
return 0;
}
a[i]=now/n;
} for(int i=0;i<=30;i++){
int cnt=0;
for(int j=1;j<=n;j++) if(a[j]&ci[i]) cnt++;
for(int j=1;j<=n;j++){
if(a[j]&ci[i]) b[j]-=cnt*ci[i],c[j]-=n*ci[i];
else c[j]-=cnt*ci[i];
}
} for(int i=1;i<=n;i++) if(c[i]||b[i]){
puts("-1");
return 0;
} for(int i=1;i<=n;i++) printf("%d ",a[i]);
return 0;
}

  


Codeforces 734 F Anton and School的更多相关文章

  1. 【codeforces 734F】Anton and School

    [题目链接]:http://codeforces.com/problemset/problem/734/F [题意] 给你两个数组b和c; 然后让你找出一个非负数组a满足题中所给关系; [题解] 有个 ...

  2. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  3. Codeforces 835 F. Roads in the Kingdom

    \(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...

  4. Codeforces 785 D.Anton and School - 2(组合数处理)

    Codeforces 785 D.Anton and School - 2 题目大意:从一串由"(",")"组成的字符串中,找出有多少个子序列满足:序列长度为偶 ...

  5. Codeforces 785 E. Anton and Permutation(分块,树状数组)

    Codeforces 785 E. Anton and Permutation 题目大意:给出n,q.n代表有一个元素从1到n的数组(对应索引1~n),q表示有q个查询.每次查询给出两个数l,r,要求 ...

  6. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  7. Codeforces Round #379 (Div. 2) F. Anton and School

    题意: 给你n对 b[i], c[i], 让你求a[i],不存在输出-1 b[i] = (a[i] and a[1]) + (a[i] and a[2]) + (a[i] and a[3]) +... ...

  8. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. "帮你"-用户模板和用户场景

    场景/故事/story 典型用户: 用户性质 典型用户介绍 姓名 小李 年龄 20岁 职业 学生 代表的用户在市场上的比例和重要性 代表学校内广大普通学生,因此有很大的重要性. 使用本软件的典型场景 ...

  2. socketCluster 使用

    <html> <head> <title>test</title> <script src="https://cdn.bootcss.c ...

  3. 【Reverse Integer】cpp

    题目: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click ...

  4. alert(1) to win部分解题

    XSS在线习题分析 (https://alf.nu/alert1) 1. Warmup function escape(s) { return '<script>console.log(& ...

  5. SDRAM学习(二)之初始化

    目录 1.SDRAM初始化的内容(结合英文数据手册) 2.SDRAM初始化的时序 3.代码的编写 4.modesim的仿真 SDRAM初始化的内容 SDRAMs must be powered up ...

  6. springcloud 高可用分布式配置中心

    SpringCloud教程七:高可用的分布式配置中心(SpringCloud Config) 当服务有很多 都要从服务中心获取配置时 这是可以将服务中心分布式处理 是系统具备在集群下的大数据处理 主要 ...

  7. 导入goshop2(复制自己看)

    1.goshop2采用了分布式的架构,很好的使用dubbo集成了服务.导入goshop2需要注意的事项如下: 1.1基本模块的架构: goshop-common开头的为项目的通用配置 goshop-s ...

  8. ALPHA(五)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  9. HDU3018 几笔画(非1笔)

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  10. 【bzoj1189】[HNOI2007]紧急疏散evacuate BFS最短路+动态加边网络流

    题目描述 发生了火警,所有人员需要紧急疏散!假设每个房间是一个N M的矩形区域.每个格子如果是'.',那么表示这是一块空地:如果是'X',那么表示这是一面墙,如果是'D',那么表示这是一扇门,人们可以 ...