CF814B.An express train to reveries

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.

On that night, Sengoku constructed a permutation _p_1, _p_2, ..., p__n of integers from 1 to n inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with n meteorids, colours of which being integer sequences _a_1, _a_2, ..., a__n and _b_1, _b_2, ..., b__n respectively. Meteoroids' colours were also between 1 and n inclusive, and the two sequences were not identical, that is, at least one i (1 ≤ i ≤ n) exists, such that a__i ≠ b__i holds.

Well, she almost had it all — each of the sequences a and b matched exactly n - 1 elements in Sengoku's permutation. In other words, there is exactly one i (1 ≤ i ≤ n) such that a__i ≠ p__i, and exactly one j (1 ≤ j ≤ n) such that b__j ≠ p__j.

For now, Sengoku is able to recover the actual colour sequences a and b through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.

千年前,千代子依然记得她和拉拉酱小时候发现的那些神秘的“彩色流星体”。尤其是其中一夜给她留下了深刻的印象,让她产生了所有幻想都将成真的错觉。

那一夜,千代子构造了一个由 11 到 nn(含)的所有整数组成的排列 p1, p2, …, pnp_1,\,p_2,\,\dots,\,p_n,其中每个整数代表一种颜色,她以此许愿,期盼即将到来的流星雨中能见到这些色彩。随后,两场惊人的流星雨接连而至,每场都包含 nn 颗流星体,其颜色分别构成整数序列 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n 和 b1, b2, …, bnb_1,\,b_2,\,\dots,\,b_n。流星体的颜色也均在 11 到 nn(含)之间,且这两个序列互不相同,即至少存在一个下标 ii(1≤i≤n1\le i\le n),使得 ai≠bia_i \ne b_i 成立。

事实上,她几乎如愿以偿——序列 aa 和 bb 各自与千代子的排列 pp 恰好有 n−1n-1 个位置上的元素相同。换言之,恰好存在一个下标 ii(1≤i≤n1\le i\le n),使得 ai≠pia_i \ne p_i;也恰好存在一个下标 jj(1≤j≤n1\le j\le n),使得 bj≠pjb_j \ne p_j。

如今,千代子已能通过天文记录复原出实际的颜色序列 aa 和 bb,但她当年许下的愿望却早已遗忘。你的任务是重构出任意一个千代子在那晚可能构造出的排列 pp。

输入格式

The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.

The second line contains n space-separated integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ n) — the sequence of colours in the first meteor outburst.

The third line contains n space-separated integers _b_1, _b_2, ..., b__n (1 ≤ b__i ≤ n) — the sequence of colours in the second meteor outburst. At least one i (1 ≤ i ≤ n) exists, such that a__i ≠ b__i holds.

输入的第一行包含一个正整数 nn(2≤n≤1 0002 \leq n \leq 1\,000)——即仙谷排列的长度,也即两次流星爆发序列的共同长度。

第二行包含 nn 个用空格分隔的整数 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n(1≤ai≤n1 \leq a_i \leq n)——第一次流星爆发的颜色序列。

第三行包含 nn 个用空格分隔的整数 b1, b2, …, bnb_1,\,b_2,\,\dots,\,b_n(1≤bi≤n1 \leq b_i \leq n)——第二次流星爆发的颜色序列。至少存在一个下标 ii(1≤i≤n1 \leq i \leq n),使得 ai≠bia_i \neq b_i 成立。

输出格式

Output n space-separated integers _p_1, _p_2, ..., p__n, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.

Input guarantees that such permutation exists.

输出 n 个用空格分隔的整数 _p_₁, _p_₂, ..., p__n,表示一条 Sengoku 可能拥有的排列。若存在多个可能的答案,输出其中任意一个即可。

输入保证这样的排列一定存在。

输入输出样例

  • 输入#1

    5
    1 2 3 4 3
    1 2 5 4 5

    输出#1

    1 2 5 4 3
  • 输入#2

    5
    4 4 2 3 1
    5 4 5 3 1

    输出#2

    5 4 2 3 1
  • 输入#3

    4
    1 1 3 4
    1 4 3 4

    输出#3

    1 2 3 4

说明/提示

In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.

In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.

在第一个样例中,1, 2, 5, 4, 3 和 1, 2, 3, 4, 5 均为可接受的输出。

在第二个样例中,5, 4, 2, 3, 1 是唯一满足约束条件的排列。

输入解题思路,AI测评打分。不知道怎么写?

首页