Company: Algo University SDE 2nd round_21april
Difficulty: medium
A photographer is trying to capture one perfect shot of N kids standing in a very particular lineup order A [1 ... N ] for the yearly family portrait. The kids, however, can't resist goofing around. Every time the photographer counts down and snaps the shutter, one kid might slip out of place and dart somewhere else in the line, purely for laughs. This happens across five separate photos. Luckily, at most one kid pulls this stunt per photo (sometimes none at all), and no kid repeats the trick in a second photo. Each of the 5 photos shows a lineup differing from the intended order A by at most one displaced kid. Whichever kid moves in one photo stays put in every other photo. Your job is to help the photographer reconstruct the intended lineup A from these 5 disorderly photos. Input Format: The first line contains a single integer N (1 ≤ N ≤ 20,000): the number of kids. The next 5 lines each contain N space-separated integers. Each line represents the lineup of kids in a single ph