#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define endl codeforces #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) using ll = std::int64_t; using ull = std::uint64_t; using pii = std::pair; using tii = std::tuple; using pll = std::pair; using tll = std::tuple; template using vec = std::vector; template using vvec = vec>; template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template T make_v(T init) { return init; } template auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec(s, v); } template struct multi_dem_array { using type = std::array::type, Head>; }; template struct multi_dem_array { using type = std::array; }; template using mdarray = typename multi_dem_array::type; namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } vec solve() { auto emp = vec(); ll n, p, q; std::cin >> n >> p >> q; p--; q--; vec pv(n); for (ll &e : pv) { std::cin >> e; e--; } std::set st; for (ll i = 0; i < n; i++) st.insert(i); vec used(n, false); std::stack stk; for (ll i = 0; i < n; i++) { ll e = pv[i]; if (e != p && e != q) { used[e] = true; stk.push(e); st.erase(e); continue; } ll idx = i; while (true) { ll cur = pv[idx]; ll val = -1; for (auto ite = st.upper_bound(cur); ite != st.end(); ++ite) { if (*ite == p || *ite == q) continue; val = *ite; break; } if (val != -1) { stk.push(val); used[val] = true; st.erase(val); break; } if (stk.empty()) return emp; ll e = stk.top(); stk.pop(); used[e] = false; st.insert(e); idx--; } break; } vec ans(n); ll idx = stk.size(); { ll tmp = idx; while (stk.size()) { ans[tmp - 1] = stk.top(); stk.pop(); tmp--; } } while (st.size()) { auto ite = st.begin(); if (*ite == q && !used[p]) ite = std::next(ite); ll e = *ite; ans[idx++] = e; used[e] = true; st.erase(e); } return ans; } int main() { std::cout << "-1\n"; return 0; auto ans = solve(); if (ans.empty()) { assert(false); std::cout << "-1\n"; } else { ll n = ans.size(); for (ll i = 0; i < n; i++) std::cout << ans[i] + 1 << " \n"[i + 1 == n]; } return 0; }