Under construction

Still being built. Things may change

Bit Operations

Time limit1sMemory limit512 MB

Summary
Given N pairs of 8-bit inputs and outputs, build a C expression using x, constants, ~, &, |, ^, +, -, and * that maps each x_i to y_i.
Level

Medium6 of 10

Topics
Bit manipulation, Brute force, Implementation
Solved
No attempts yet

Problem

You are given NN pairs (xi,yi)(x_i, y_i). Construct a function ff that satisfies yi=f(xi)y_i = f(x_i) for each ii. The function ff must be writable in C in the following form:

uint32_t f(uint32_t x) {
  return Expression;
}

The Expression must satisfy the following BNF:

<expr> ::= "x"
         | <num>
         | "(~" <expr> ")"
         | "(" <expr> <op2> <expr> ")"
<op2> ::= "&" | "|" | "^" | "+" | "-" | "*"

Here, is an unsigned 32-bit integer written in decimal. It must not have leading zeroes, except that zero is written as 00.

Input

The first line contains an integer NN (1≤N≤81 \le N \le 8). The next NN lines each contain two integers xix_i and yiy_i (0≤xi,yi<2560 \le x_i, y_i < 256).

Output

Print an expression that satisfies the conditions. The output must strictly follow the BNF format above. Extra whitespace, newlines, parentheses, and other characters are not allowed. The output must contain at most 10510^5 characters. The answer is guaranteed to exist for the given input.

Examples2

  1. Example 1

    Input
    8
    1 1
    2 2
    3 3
    4 0
    5 1
    6 2
    7 3
    8 0
    
    Expected output
    (x&3)
    
  2. Example 2

    Input
    8
    1 0
    2 0
    3 2
    4 0
    5 4
    6 4
    7 6
    8 0
    
    Expected output
    (x&(x-1))