#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> vis(n + 1), bel(n + 1), sz(n + 1), cir(n + 1);
vector<int> stk(n + 1), instk(n + 1); int tp = 0;
for(int i = 1; i <= n; i++) if(!vis[i]) {
auto dfs = [&](this auto &&self, int x) -> void {
vis[x] = 1, stk[++tp] = x, instk[x] = 1;
if(bel[a[x]]) {
bel[x] = bel[a[x]], sz[bel[x]]++;
} else if(vis[a[x]]) {
while(stk[tp] != a[x]) {
cir[x]++, sz[x]++;
bel[stk[tp]] = x;
instk[stk[tp]] = 0;
tp--;
}
cir[x]++, sz[x]++, bel[a[x]] = x, instk[a[x]] = 0, tp--;
} else {
self(a[x]);
}
if(instk[x]) tp--, instk[x] = 0;
};
dfs(i);
}
vector<int> ve, ans(n + 2);
for(int i = 1; i <= n; i++) {
if(bel[i] == i) {
ve.push_back(sz[i]);
ans[cir[i]]++, ans[sz[i] + 1]--;
}
}
for(int i = 1; i <= n; i++) ans[i] += ans[i - 1];
for(int i = 1; i <= n; i++) ans[i] = !ans[i];
sort(ve.begin(), ve.end(), greater<int>());
for(int i = 1; i < ve.size(); i++) ve[i] += ve[i - 1];
for(int i = 1; i < ve.size(); i++) {
for(int j = ve[i - 1] + 1; j <= ve[i]; j++) {
ans[j] = i;
}
}
for(int i = 1; i <= n; i++) {
cout << ans[i] << " \n"[i == n];
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}