#P15052. [UOI 2023 II Stage] Memory training

    ID: 16982 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>模拟2023排序双指针 two-pointerUOI(乌克兰)

[UOI 2023 II Stage] Memory training

题目描述

Vasyl and Petro are training their memories. To do this, they take an array A[1..n]A[1..n] with nn elements and perform the following actions:

  • First, Vasyl takes any number from the array, and names all other elements of the array at random.
  • Then Petro takes any number from the array named by Vasyl, and names all other elements of that array at random.
  • Then Vasyl performs his turn again.
  • Then Petro performs his turn.
  • And so on.

Obviously, after nn moves, all elements of the array AA will be distributed between Vasyl and Petro.

Let's take a look at an example of how memory training works. Let the initial array be A=[1  2  3  4  5  6]A = [1\; 2\; 3\; 4\; 5\; 6].

  • Vasyl makes the first move: [3  6  1  2  4][3\; 6\; 1\; 2\; 4]. He took number 55 and named all other elements of the array AA at random.
  • Then Petro names this array: [2  6  3  4][2\; 6\; 3\; 4]. He took number 11 for himself.
  • Vasyl names this array: [3  4  6][3\; 4\; 6]. He took number 22 for himself.
  • Petro names this array: [4  3][4\; 3]. He took number 66 for himself.
  • Vasyl names this array: [3][3]. He took number 44 for himself.
  • Petro takes the last number, 33 for himself.
  • Thus, Vasyl received the numbers [2  4  5][2\;4\; 5], and Petro received the numbers [1  3  6][1\; 3\; 6].

Write a program that, given an input array and the sequence of actions, determines who got which elements.

输入格式

The first line contains a single integer nn (2n10002 \leq n \leq 1\,000) --- the number of elements in the array.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (109ai109-10^9 \leq a_i \leq 10^9).

Each of the following (n1)(n-1) lines contains an array, which was named by either Vasyl or Petro. It is guaranteed that the arrays are correct, that is, each of them can be obtained from the previous one.

输出格式

In the first line, output the elements that Vasyl took in non-descending order.

In the second line, output the elements that Petro took in non-descending order.

6
1 2 3 4 5 6
3 6 1 2 4
2 6 3 4
3 4 6
4 3
3
2 4 5 
1 3 6 
5
1 8 4 2 100
2 4 100 8
100 2 8
2 8
2
1 2 100 
4 8 

提示

In this problem, each test is evaluated separately. However, further:

  • In 22%22\% of the tests, each integer from 11 to nn occurs exactly once in the initial array AA.
  • In 35%35\% of the tests, n10n \leq 10.