eolymp
bolt
Try our new interface for solving problems
Problems

Seating Chart

Seating Chart

Bilbo's birthday is coming up, and Frodo and Sam are in charge of all the party planning! They have invited all the hobbits of Middle Earth to the party, and everyone will be sitting in a single row at an extremely long dining table. However, due to poor communication, Frodo and Sam have each independently put together a seating chart for all the hobbits at the dining table. Help Frodo and Sam nd out how similar their seating charts are by counting the total number of distinct pairs of hobbits who appear in different orders in the two charts. \InputFile Contains multiple test cases. Each test case begins with a single line containing the number of hobbits \textbf{n }(\textbf{1 }≤ \textbf{ n }≤ \textbf{100000}). The next two lines represent Frodo's and Sam's seating charts, respectively. Each seating chart is specified as a single line of \textbf{n }unique alphabetical strings; the set of strings in each line are guaranteed to be identical. The end-of-input is denoted by a line containing the number \textbf{0}. \OutputFile For each test case output a single integer denoting, out of the \textbf{n }choose \textbf{2} distinct pairs of hobbits, how many pairs appear in dierent orders in Frodo's and Sam's seating arrangements.
Time limit 10 seconds
Memory limit 64 MiB
Input example #1
3
Frodo Sam Bilbo
Sam Frodo Bilbo
5
A B C D E
B A D E C
0
Output example #1
1
3
Source 2012 North America - Pacific Northwest Region Programming Contest, November 3, Problem H