O-Longest
You are given square matrix NxN containing English uppercase letters.
Find longest word which have every letter greater then previous (lexicographically). You can create word by following this rules:
- You can start from any letter in matrix,
- From every letter you can go in four direction: up, left, down, right.
In 50% tests N <= 5.
InputIn first line on input is one integer N (1 <= N <= 100).
In next N lines there are N English uppercase letter in each line.
In next N lines there are N English uppercase letter in each line.
OutputIn only line on output write longest word which collected from given matrix with rules defined above.
If there are multiple solution, print any of them.
If there are multiple solution, print any of them.
Input:
2
AB
CD
Output:
ABD
Input:
4
SOKA
KOKA
KOLU
LOKA
Output:
AKOS
EXPLANATION: in first example one more correct is ACD. In second example correct answers are AKLU and AKLO as well.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.