Hide

Problem B
Make Things Even

Helena has been very busy preparing for EGOI. Her preparation involved a lot of different problems containing various numbers, and she has trouble remembering all of them. She has a brilliant idea: she will ask her friend Eva, who has an amazing memory, for help with remembering the numbers.

Eva likes things to be even! She refuses to remember numbers that are odd (test groups 1 and 2) or that just contain an odd digit (test groups 3 and 4).

Can you help Helena come up with a way to transform the numbers she wants to remember so that Eva will remember them? Of course she also needs to be able to reverse the computation and get her original number back.

Implementation

This is a multirun problem, meaning that your program will be executed multiple times.

The input contains two integers, $P$ and $N$, where $P$ is either $1$ or $2$ (first or second phase), and $N$ is the number to be processed in this round.

The following output depends on the phase:

Phase 1

In the first phase, you should output a number $A$, the number that you want to tell to Eva to remember. This number will be used as the input for your program in Phase 2.

Phase 2

In this phase, you should output the original number that Helena wanted to remember from the number that you produced in the first phase.

Details.

If the sum of the running times of the two separate runs of your program exceeds the time limit, your submission will be judged as Time Limit Exceeded.

Make sure to flush standard output after printing each line, or else your program might get judged as Time Limit Exceeded. In Python, this happens automatically as long as you use input() to read lines. In C++, cout << endl; flushes in addition to printing a newline; if using printf, use fflush(stdout).

Constraints and Scoring

  • $1\le N \le 1\, 919\, 191$.

  • In all cases, the number you output in Phase 1, $A$, needs to satisfy $0\le A\le 1\, 000\, 000\, 000$.

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group, you need to solve all test cases in the test group.

Group

Score

Constraints

1

12

$A$ has to be even and $N\le 100$.

2

14

$A$ has to be even.

3

31

$A$ can only contain even digits and $N\le 100$.

4

43

$A$ can only contain even digits.

Testing Tool

To facilitate the testing of your solution, we provide a simple tool that you can download. See ‘attachments’ at the bottom of the Kattis problem page. The tool is optional to use. Note that the official grader program on Kattis is different from the testing tool.

To use the tool, create an input file, such as ‘sample1.in’, which should contain the number $N$ that your program will be tested with.

For Python programs, say solution.py (normally run as pypy3 solution.py):

python3 testing_tool.py pypy3 solution.py < sample1.in

For C++ programs, first compile it (e.g. with g++ -g -O2 -std=gnu++23 -static solution.cpp -o solution.out) and then run:

python3 testing_tool.py ./solution.out < sample1.in

Example

In the samples below, the first two executions correspond to sample1, and the latter two correspond to sample2.

Read Sample Interaction 1 Write
1 7
28
Read Sample Interaction 2 Write
2 28 
7
Read Sample Interaction 3 Write
1 191919
202020
Read Sample Interaction 4 Write
2 202020
191919

Please log in to submit a solution to this problem

Log in