#P10244. Lexicographical Minimization of Strings

    ID: 12241 Type: Default 1000ms 256MiB

Lexicographical Minimization of Strings

Lexicographical Minimization of Strings

Given four strings of length \(n\): \(a\), \(b\), \(c\), and \(d\). You can perform the following operation any number of times: choose an index \(i\) (1-indexed or 0-indexed depending on your implementation) and swap \(a_i\) with \(c_i\) and simultaneously swap \(b_i\) with \(d_i\). Your goal is to achieve the lexicographically smallest possible string \(a\). Among all operations that achieve this minimum \(a\), determine the lexicographically smallest possible string \(b\).

The lexicographical order between two strings \(p\) and \(q\) is defined as follows: \(p < q\) if and only if there exists a natural number \(k\) such that the first \(k\) characters of \(p\) and \(q\) are identical and the \((k+1)\)th character of \(p\) has a smaller ASCII value than that of \(q\). For example, \(\texttt{abc} < \texttt{baa}\) (with \(k=0\)) and \(\texttt{bae} < \texttt{bbb}\) (with \(k=1\)).

inputFormat

The first line contains an integer (n). The next four lines contain the strings (a), (b), (c), and (d) respectively.

outputFormat

Output a single line containing the lexicographically smallest possible string (b) after applying the operations to minimize (a).

sample

5
abcde
fghij
bbcde
agijk
fghij