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 

import sys

n = int(sys.stdin.readline())
a = [int(u)-1 for u in sys.stdin.readline().split()]    # fathers

parents = [None] * n

queue = []
opened = [False] * n
closed = [False] * n

for i in xrange(n):
    if closed[i]:
        continue
    assert not opened[i]
    
    queue.append(i)
    
    while len(queue) > 0:
        x = queue[-1]
        
        if a[x] == x:
            opened[x] = True
            closed[x] = True
            parents[x] = x
            queue.pop()
        
        elif closed[x]:
            queue.pop()
        
        elif opened[x]:
            closed[x] = True
            if parents[a[x]] is not None:
                parents[x] = parents[a[x]]
            else:
                # loop
                parents[x] = x
            queue.pop()
        
        else:
            opened[x] = True
            queue.append(a[x])

# print parents

relevant = list(set(parents))
# print relevant

# choose root
root = relevant[0]
for x in relevant:
    if a[x] == x:
        root = x

# do changes
num_changes = 0
for x in relevant:
    if a[x] != root:
        a[x] = root
        num_changes += 1

print num_changes
for x in xrange(n):
    print a[x]+1,



