C. Short Program
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.

In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.

Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.

Input

The first line contains an integer n (1 ≤ n ≤ 5·105) — the number of lines.

Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023.

Output

Output an integer k (0 ≤ k ≤ 5) — the length of your program.

Next k lines must contain commands in the same format as in the input.

Examples
Input
3
| 3
^ 2
| 1
Output
2
| 3
^ 2
Input
3
& 1
& 3
& 5
Output
1
& 1
Input
3
^ 1
^ 2
^ 3
Output
0
Note

You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation.

Second sample:

Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.

/*
题意:给出一段程序,只有三种操作,^ & |,然后让你输出一段不超过5行的程序使得运算结果和给出程序的运算结果相同 思路:经过如果操作之后,总共十位二进制数,有:确定为1的,确定为0的,不变的,是原来的相反的,然后分别讨论四种
情况
*/
#include <bits/stdc++.h> #define MAXN 500005
#define MAXK 2 using namespace std; int n;
char str[MAXN][MAXK];
int a[MAXN];
int ora,xora,anda; inline int cal(int x){
for(int i=;i<n;i++){
switch(str[i][]){
case '^':
x^=a[i];
break;
case '&':
x&=a[i];
break;
case '|':
x|=a[i];
break;
} }
return x;
} inline void init(){
ora=;
xora=;
anda=;
} int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%s%d",str[i],&a[i]);
}
int pos=cal();
for(int i=;i<;i++){
int cur=cal((<<i));
if(( cur&(<<i) )==&&( pos&(<<i) )==){//如果这一位肯定为0 }else if(( cur&(<<i) )!=&&( pos&(<<i) )!=){//这位肯定为1
anda+=(<<i);
ora+=(<<i);
}else if(( cur&(<<i) )==&&( pos&(<<i) )!=){//这位和原来相反
anda+=(<<i);
xora+=(<<i);
}else{//这位不变
anda+=(<<i);
}
}
printf("3\n");
printf("& %d\n",anda);
printf("| %d\n",ora);
printf("^ %d\n",xora);
return ;
}

Codeforces Round #443 (Div. 2) C. Short Program的更多相关文章

  1. Codeforces Round #443 (Div. 1) A. Short Program

    A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new progr ...

  2. Codeforces Round #443 (Div. 2) C: Short Program - 位运算

    传送门 题目大意: 输入给出一串位运算,输出一个步数小于等于5的方案,正确即可,不唯一. 题目分析: 英文题的理解真的是各种误差,从头到尾都以为解是唯一的. 根据位运算的性质可以知道: 一连串的位运算 ...

  3. Codeforces Round #879 (Div. 2) C. Short Program

    题目链接:http://codeforces.com/contest/879/problem/C C. Short Program time limit per test2 seconds memor ...

  4. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  5. Codeforces Round #443 (Div. 2)

    C. Short Program Petya learned a new programming language CALPAS. A program in this language always ...

  6. Codeforces Round #443 (Div. 2) C 位运算

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. 【Codeforces Round #443 (Div. 2) C】Short Program

    [链接] 我是链接,点我呀:) [题意] 给你一个n行的只和位运算有关的程序. 让你写一个不超过5行的等价程序. 使得对于每个输入,它们的输出都是一样的. [题解] 先假设x=1023,y=0; 即每 ...

  8. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  9. Codeforces Round #443 Div. 1

    A:考虑每一位的改变情况,分为强制变为1.强制变为0.不变.反转四种,得到这个之后and一发or一发xor一发就行了. #include<iostream> #include<cst ...

随机推荐

  1. JVM菜鸟进阶高手之路五

    转载请注明原创出处,谢谢! 参考gc,发现大概一小时运行一次FGC,特别奇怪,笨神一看这样的问题就知道是system gc导致的,rmi默认一小时主动触发一次,由于没有gc日志,通过jstat命令观察 ...

  2. 翻译连载 | 第 9 章:递归(下)-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇

    原文地址:Functional-Light-JS 原文作者:Kyle Simpson-<You-Dont-Know-JS>作者 关于译者:这是一个流淌着沪江血液的纯粹工程:认真,是 HTM ...

  3. JAVA设计模式总结之六大设计原则

    从今年的七月份开始学习设计模式到9月底,设计模式全部学完了,在学习期间,总共过了两篇:第一篇看完设计模式后,感觉只是脑子里面有印象但无法言语.于是决定在看一篇,到9月份第二篇设计模式总于看完了,这一篇 ...

  4. PyTorch教程之Neural Networks

    我们可以通过torch.nn package构建神经网络. 现在我们已经了解了autograd,nn基于autograd来定义模型并对他们有所区分. 一个 nn.Module模块由如下部分构成:若干层 ...

  5. python GUI实战项目——tkinter库的简单实例

    一.项目说明: 本次通过实现一个小的功能模块对Python GUI进行实践学习.项目来源于软件制造工程的作业.记录在这里以复习下思路和总结编码过程.所有的源代码和文件放在这里: 链接: https:/ ...

  6. JS判断访问设备是移动设备还是pc

    <scripttype="text/javascript"> function browserRedirect() { var sUserAgent= navigato ...

  7. hadoop各个名词的理解

    Hadoop家族的各个成员 hadoop这个词已经流行好多年了,一提到大数据就会想到hadoop,那么hadoop的作用是什么呢? 官方定义:hadoop是一个开发和运行处理大规模数据的软件平台.核心 ...

  8. 使用siege对web接口进行post方式的压力测试

    为了达到压力测试的效果,需要申请一台线上机器,并且安装压力测试的工具siege. 安装新版siege.资料说yum安装的版本2.70对于post方式支持的不好,验证后发现请求可以正常发过去,但是打开d ...

  9. Entity Framework 之Code First自动数据迁移

    using MvcShopping.Migrations; using MvcShopping.Models; using System; using System.Collections.Gener ...

  10. 使用jquery.form.js文件进行文件上传

    本想着文件上传是一件挺简单的事,不过是获取文件地址保存到服务器而已,然而事实并非如此. 我信心满满的写下input type="file",alert input 的value,打 ...