#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
const int lim = 1e3 + 5;
vector<int> adj(lim);
vector<int> revadj[lim];
vector<int> res(lim, -1);
void revdfs(int node, int answer) {
  for (auto u : revadj[node]) {
    if (res[u] == -1) {
      res[u] = answer;
      revdfs(u, answer);
    }
  }
}
void dfs(int elem) {
  int slow = elem, fast = elem;
  do {
    slow = adj[slow];
    fast = adj[adj[fast]];
  } while (slow != fast);
  slow = elem;
  while (slow != fast) {
    slow = adj[slow];
    fast = adj[fast];
  }
  do {
    res[fast] = fast;
    fast = adj[fast];
  } while (fast != slow);
  revdfs(slow, slow);
}
void pre_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int32_t main() {
  pre_io();
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> adj[i];
  for (int i = 1; i <= n; i++) revadj[adj[i]].push_back(i);
  for (int i = 1; i <= n; i++) {
    if (res[i] == -1) dfs(i);
  }
  for (int i = 1; i <= n; i++) cout << res[i] << " ";
}
