Skip to main content
Back to problems
Codeforces
Easy
Arrays
Presents

Given a permutation describing who gave a present to whom, reconstruct the final arrangement so that each child gets the present intended for them.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

There are nn children numbered from $1toton.Eachchildgaveapresenttoexactlyoneotherchild,andeverychildreceivedexactlyonepresent.Theinformationisgivenasapermutation. Each child gave a present to exactly one other child, and every child received exactly one present. The information is given as a permutation poflengthof lengthn,where, where p_imeansthemeans theithchildgavetheirpresenttochild-th child gave their present to child p_i$.

Your task is to determine, for every child ii, which child gave a present to them.

In other words, output the inverse permutation.

Task

For each child ii from $1toton,findtheindex, find the index jsuchthatsuch thatp_j = i$.

Input Format

  • The first line contains an integer nn.
  • The second line contains nn integers p1,p2,,pnp_1, p_2, \dots, p_n — a permutation of $1..n$.

Output Format

  • Print nn integers a1,a2,,ana_1, a_2, \dots, a_n where aia_i is the child who gave a present to child ii.

Constraints

  • 1n1051 \le n \le 10^5
  • pp is a permutation of $1..n$
  • Time limit friendly solution: O(n)O(n)
Examples
Sample cases returned by the problem API.

Example 1

Input

4
2 3 4 1

Output

4 1 2 3

Explanation

Child 1 received a present from child 4, child 2 from child 1, child 3 from child 2, and child 4 from child 3.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.