PivotOJ

Pawn Shop

시간 제한: 2000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2021BOJ 24754

문제

You run a tight ship at the pawn shop. You arrange certain items in the window to be displayed to the street. You sometimes display the same type of item multiple times. For simplicity, we think of the items on display as a sequence of values where the value represents the type of item being shown.

For example, your display could be this sequence: \[ 1~~2~~6~~2~~7~~9~~8~~5 \]

After coming back from your latest vacation, you find that your staff has completely rearranged the display by moving items around. Yikes! For example, the display above could be rearranged to: \[ 2~~6~~1~~2~~9~~7~~5~~8 \]

You fear this could be the cause of confusion and may scare off repeat customers. But you don't have time to move items back to their original positions.

As a compromise, you will put dividers up in the window to partition the displayed items into groups of consecutive items. Each group should be a rearrangement of the types of items that were in those positions in your preferred arrangement.

More precisely, let a1,,aNa_1, \ldots, a_N denote the first sequence and b1,,bNb_1, \ldots, b_N denote the second sequence. You may place dividers around i,i+1,,ji, i+1, \ldots, j if bi,bi+1,,bjb_i, b_{i+1}, \ldots, b_j is a rearrangement of ai,ai+1,,aja_i, a_{i+1}, \ldots, a_j. You do not need to put a divider at the beginning or end of the sequence. Note, if ai=bia_i = b_i then a group may be formed using just this single index ii.

With the sequences above, you could place dividers # at three positions as indicated here: \[ 2~~6~~1~~\texttt{#}~~2~~\texttt{#}~~7~~9~~\texttt{#}~~5~~8 \]

It is not possible to divide the sequence into more than four groups that have this property.

Given the two sequences, determine how to partition the new sequence into the maximum possible number of groups.

입력

The first line of input contains a single integer NN (1N3000001 \leq N \leq 300\,000), which is the length of the two sequences.

The next line contains NN integers a1,,aNa_1, \ldots, a_N (1ai1091 \leq a_i \leq 10^9), which is the original sequence.

The next line contains NN integers b1,,bNb_1, \ldots, b_N (1bi1091 \leq b_i \leq 10^9), which is the rearranged sequence. The values b1,,bNb_1, \ldots, b_N are a rearrangement of the values a1,,aNa_1, \ldots, a_N.

출력

Display the rearranged sequence with a valid and maximum placing of dividers (#).

If there are multiple possible solutions, display any of them.

예제

예제 1

입력
8
1 2 6 2 7 9 8 5
2 6 1 2 9 7 5 8
출력
2 6 1 # 2 # 9 7 # 5 8

예제 2

입력
4
1 1 2 1
2 1 1 1
출력
2 1 1 # 1

예제 3

입력
3
1 2 5
2 5 1
출력
2 5 1
코드를 제출하려면 로그인하세요.