#P10293. [CCC 2024 J4] Troublesome Keys

[CCC 2024 J4] Troublesome Keys

Problem Description

Alex’s keyboard is strange. Two letter keys are malfunctioning:

  • There is one key on the keyboard that always shows a different, wrong letter every time it is pressed. Alex calls this key the troublesome key. Strangely, Alex has never tried to type this wrong letter.
  • There is another key on the keyboard that shows nothing when it is pressed. Alex calls this key the silent key.

Alex has pressed the troublesome key at least once, but may not have pressed the silent key.

You need to determine which keys are malfunctioning and, for the troublesome key, which wrong letter it displays when pressed. Luckily, this is possible because Alex never pressed the silent key immediately after pressing the troublesome key, and also never pressed the troublesome key immediately after pressing the silent key.

Input Format

The input consists of two lines. The first line contains the NN keys that Alex pressed. The second line contains the letters shown on the screen.

Output Format

The output consists of two lines.

On the first line, output two letters separated by a space: the troublesome key and the wrong letter it displays when pressed.

On the second line, output one character. If the silent key was pressed, output the silent key; otherwise, output a hyphen (-).

forloops
fxrlxxps
o x
-
forloops
fxrlxxp
o x
s
forloops
frlpz
s z
o

Hint

[Sample 1 Explanation]

The letter corresponding to the troublesome key is o, and each press shows the wrong letter x. The silent key was not pressed.

[Sample 2 Explanation]

The letter corresponding to the troublesome key is o, and each press shows the wrong letter x. The silent key that shows nothing corresponds to the letter s.

[Sample 3 Explanation]

The letter corresponding to the troublesome key is s, and each press shows the wrong letter z. The silent key that shows nothing corresponds to the letter o.

[Constraints]

This problem uses bundled testdata.

For all testdata, each input line contains only lowercase letters, and 1N5×1051\leq N\leq 5\times 10^5.

The table below shows the distribution of the 1515 points:

Score Description Range
33 The silent key was not pressed, and the number of key presses is small. N50N \leq 50
The first malfunctioning key pressed is the troublesome key, and the number of key presses is small.
55 The first malfunctioning key pressed may be the troublesome key or the silent key, and the number of key presses is small.
44 The first malfunctioning key pressed may be the troublesome key or the silent key, and the number of key presses may be large. N5×105N \leq 5 \times 10^5

Translated by ChatGPT 5