#P8040. [COCI 2016/2017 #7] IGRA

[COCI 2016/2017 #7] IGRA

Background

Mirko and Slavko are very bored with their ski trip, so they start playing a new game.

Problem Description

First, Mirko chooses an integer NN, then Slavko writes down NN letters, and Mirko writes down a word of length NN. Slavko needs to use the NN letters he wrote down to form a word, and in his word, there must be no position where the letter is the same as the letter in the corresponding position of Mirko’s word. To make the game challenging, Mirko also requires that Slavko’s word be the lexicographically smallest among all words that satisfy the requirement. This word is guaranteed to exist. Since Mirko and Slavko are still young, they only know the three letters a, b, and c, so the words they write will also contain only these three letters.

Please help Slavko find such a word.

Input Format

The first line contains an integer NN, the number of letters in the words written by Mirko and Slavko.
The second line contains a string of length NN, representing all the letters included in the word written by Slavko.
The third line contains a string of length NN, representing the word written by Mirko.

Output Format

Output one line with a string of length NN, the lexicographically smallest string that satisfies the requirement.

For two strings a,ba, b of length NN, aa is lexicographically smaller than bb if and only if there exists an integer p[1,N]p\in[1,N] such that i[1,p)\forall i\in[1,p), ai=bia_i=b_i, and ap<bpa_p<b_p.

3
abc
abc
bca
4
baba
baab
abba
5
aaabc
abcba
baaac

Hint

Constraints

For 40%40\% of the testdata, 1N201\leqslant N\leqslant 20.
For all testdata, 1N50001\leqslant N\leqslant 5000, and all strings can only contain the letters a, b, c.

Source

This problem comes from COCI 2016-2017 CONTEST 7 T3 IGRA. With the original testdata configuration, the full score is 100100 points.

Translated and organized by Eason_AC.

Translated by ChatGPT 5