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 

def find_group(i):
    if group[i] != group[group[i]]:
        group[i] = find_group(group[group[i]])
    return group[i]


n = int(raw_input())
group = range(n)
size = [1] * n
roots = []
root = None

parent = map(lambda x: int(x) - 1, raw_input().split())

for i in xrange(n):
    c_group = find_group(i)
    p_group = find_group(parent[i])

    if c_group != p_group:
        if size[c_group] > size[p_group]:
            size[c_group] += size[p_group]
            group[p_group] = c_group
        else:
            size[p_group] += size[c_group]
            group[c_group] = p_group
    else:
        roots.append(i)
        if parent[i] == i:
            root = i

answer = len(roots) - 1

if root is None:
    root = roots[0]
    answer += 1

for r in roots:
    parent[r] = root

print answer
for i in xrange(n):
    print parent[i] + 1,
