Logic Operators (APCS 2017-10 Beginner)

Points 100 1.0s 256M

Su is learning three logic operators: AND, OR, and XOR. All three are binary operators, meaning each operation takes two operands, e.g. a AND b. For integers \(a\) and \(b\), the results of the three binary operators are defined by the following three tables:

a AND b \(b = 0\) \(b \ne 0\)
\(a = 0\) \(0\) \(0\)
\(a \ne 0\) \(0\) \(1\)
a OR b \(b = 0\) \(b \ne 0\)
\(a = 0\) \(0\) \(1\)
\(a \ne 0\) \(1\) \(1\)
a XOR b \(b = 0\) \(b \ne 0\)
\(a = 0\) \(0\) \(1\)
\(a \ne 0\) \(1\) \(0\)

For example:

  1. The result of 0 AND 0 is \(0\); the results of 0 OR 0 and 0 XOR 0 are also \(0\).
  2. The result of 0 AND 3 is \(0\); the results of 0 OR 3 and 0 XOR 3 are \(1\).
  3. The result of 4 AND 9 is \(1\); the result of 4 OR 9 is also \(1\), but the result of 4 XOR 9 is \(0\).

Write a program that reads \(a\), \(b\), and the result of a logic operation, and outputs which operations could have produced that result.

Input

The input is a single line containing three integers separated by single spaces. The first integer is \(a\) and the second is \(b\); both are non-negative integers. The third integer is the result of the logic operation, which is always \(0\) or \(1\).

Constraints:

  • \(0 \le a, b < 10000\)
  • The given result is always \(0\) or \(1\)

Output

Output the operations that could produce the given result. If there are multiple, output them in the order AND, OR, XOR, each on its own line, each line ending with a newline. If no operation can produce the given result, output IMPOSSIBLE. (Note that all letters in the output are uppercase.)

Scoring

The time limit for each test case is \(1\) second; your score is the sum over the test cases you pass. The subtasks are:

  • Subtask 1 (\(80\) points): \(a\) and \(b\) are each either \(0\) or \(1\).
  • Subtask 2 (\(20\) points): \(0 \le a, b < 10000\).

Sample Input 1

0 0 0

Sample Output 1

AND
OR
XOR

Sample Input 2

1 1 1

Sample Output 2

AND
OR

Sample Input 3

3 0 1

Sample Output 3

OR
XOR

Sample Input 4

0 0 1

Sample Output 4

IMPOSSIBLE

Source

APCS programming exam, October 28, 2017, Problem 1.

Problem page help

Keyboard shortcuts

Main features

  • Sample tests — Runs the sample cases bundled with the problem and auto-compares against the expected output.
  • Custom test — Run your code with your own stdin. Optionally tick the "Compare with expected (diff)" box to verify against expected output line-by-line.
  • Template — Paste the default code template you set on your profile page.
  • Collab — Edit this problem together with classmates in real time.
  • Auto-draft — Editor contents auto-save to your browser every 1.5 seconds (per account / problem / language).
  • Submit — Send your code to the judge for grading; returns AC / WA / TLE etc.

Limits

  • Source code: at most 65,536 characters
  • Custom test stdin and expected output: at most 1 MB each (≈1 million characters)
  • Custom test and sample test share the sandbox; about 1 request per 3 s per user (sample test: 1 per 1 s)
  • Custom test and sample test both have a 15 second wall-clock cap (the official judge still uses the problem time limit)
  • Interactive problems do not offer custom test (cannot simulate interaction with the judge).
  • Submitting has no rate limit, but rapid repeated submissions on the same problem are treated as score farming.