codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

878A.md (1950B)


      1 Source: https://codeforces.com/problemset/problem/878/A
      2 
      3 A. Short Program
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 Input
     28 
     29 The first line contains an integer *n* (1 ≤ *n* ≤ 5·105) — the number of lines.
     30 
     31 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 *x**i* 0 ≤ *x**i* ≤ 1023.
     32 
     33 Output
     34 
     35 Output an integer *k* (0 ≤ *k* ≤ 5) — the length of your program.
     36 
     37 Next *k* lines must contain commands in the same format as in the input.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 3  
     45 | 3  
     46 ^ 2  
     47 | 1
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 2  
     54 | 3  
     55 ^ 2
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 3  
     62 & 1  
     63 & 3  
     64 & 5
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 1  
     71 & 1
     72 ```
     73 
     74 Input
     75 
     76 ```
     77 3  
     78 ^ 1  
     79 ^ 2  
     80 ^ 3
     81 ```
     82 
     83 Output
     84 
     85 ```
     86 0
     87 ```
     88 
     89 Note
     90 
     91 You can read about bitwise operations in <https://en.wikipedia.org/wiki/Bitwise_operation>.
     92 
     93 Second sample:
     94 
     95 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.