#C8819. Book Exchange Simulation

    ID: 52843 Type: Default 1000ms 256MiB

Book Exchange Simulation

Book Exchange Simulation

Sam and Alex are two friends who both start with k books. They agree to exchange some of their books according to a list of exchanges. In each exchange, Sam gives a book with identifier \(e_i\) to Alex, and Alex gives a book with identifier \(t_i\) to Sam. After all exchanges, the number of books each friend holds remains the same as they swapped books.

Your task is to simulate the exchanges and determine the number of books each friend has at the end. It is guaranteed that the book given by one friend always exists in their collection at the time of the exchange.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains two integers \(k\) and \(n\) separated by a space, where \(k\) is the initial number of books for each friend and \(n\) is the number of exchanges.
  • The second line contains \(k\) integers representing the book IDs that Sam initially owns.
  • The third line contains \(k\) integers representing the book IDs that Alex initially owns.
  • The next \(n\) lines each contain two integers \(e_i\) and \(t_i\) separated by a space, indicating that in this exchange, Sam gives book \(e_i\) and receives book \(t_i\) from Alex.

outputFormat

Output to standard output (stdout) a single line with two integers separated by a space: the number of books Sam and Alex have after all exchanges.

## sample
3 2
1 2 3
4 5 6
1 4
2 5
3 3

</p>