3
2 1 1
 6
6 2 6 2 4 2
 2
1 2
 8
2 1 2 2 6 5 6 6
 18
2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18
 7
1 2 3 4 5 6 7
 7
4 3 2 6 3 5 2
 7
7 5 3 1 2 1 5
 7
1 6 4 4 5 6 7

1
2 2 1  0
6 2 6 2 4 2  1 
1 1 
 2 
2 2 2 2 6 2 6 6 
 5 
2 3 4 5 11 7 8 9 10 11 11 11 14 15 11 17 18 11 
 6 
1 1 1 1 1 1 1 
 1
4 3 3 6 3 5 2  1
7 5 3 1 3 1 5  4 
1 6 4 1 1 1 1 

class DSU(object):
    def __init__(self, n):
        self.p = list(range(n))
        self.rt = [None] * n
        self.rk = [0] * n

    def find(self, u):
        while u != self.p[u]:
            u = self.p[u]
        return u

    def get(self, u):
        return self.rt[self.find(u)]

    def unite(self, u, v):
        u = self.find(u)
        v = self.find(v)
        if u == v:
            return

        if self.rk[u] < self.rk[v]:
            u, v = v, u
        self.p[v] = u
        self.rk[u] += self.rk[u] == self.rk[v]

        if self.rt[v] is not None:
            self.rt[u] = self.rt[v]

n = int(input())
p = list(map(int, input().split()))

dsu = DSU(n)

for u in range(n):
    p[u] -= 1
    if p[u] == u:
        dsu.rt[u] = u

for u in range(n):
    dsu.unite(u, p[u])

rt = dsu.get(0)
if rt is None:
    rt = 0

ans = 0

for u in range(1, n):
    if u != dsu.find(rt) and u == dsu.find(u):
        v = dsu.get(u)
        if v is None:
            v = u
        p[v] = rt
        dsu.unite(v, rt)
        ans += 1

print(ans)
for u in range(n):
    p[u] += 1
print(*p)
