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 itertools
import sys


def readline_int(delta=0):
    return [int(i) + delta for i in raw_input().split()]

class Solution(object):
    def find(self, ident, fa):
        if fa[ident] != ident:
             fa[ident] = self.find(fa[ident], fa)
        return fa[ident]

    def merge(self, ident_child, ident_father, fa):
        fa_child = fa[ident_child]
        fa_father = fa[ident_father]
        fa[fa_child] = fa_father

    def solve(self):
        n = self.n
        p = self.p
        issues = []
        roots = []
        fa = [i for i in xrange(n)]

        for current in xrange(n):
            parent = p[current]
            if parent == current:
                roots.append(current)
                continue

            parent_set_id = self.find(parent, fa)
            if parent_set_id == current:
                issues.append(current)
                continue

            self.merge(current, parent, fa)

        root = None
        changes = 0
        if len(roots) > 0:
            root = roots[0]
            changes = len(roots) + len(issues) - 1
        elif len(roots) == 0:
            root = roots[0] if len(roots) > 0 else issues[0]
            changes = len(roots) + len(issues)

        for ident in itertools.chain(roots, issues):
            p[ident] = root

        return (changes, p, )

    def read_data(self):
        self.n = readline_int()[0]
        self.p = readline_int(delta=-1) # make sure to restore index while printing result

    def print_result(self, result):
        changes, p = result
        print(changes)
        for idx, parent in enumerate(p):
            sys.stdout.write(str(parent))
            if idx != len(p) - 1:
                sys.stdout.write(' ')
        sys.stdout.write('\n')


    def run(self):
        self.read_data()
        result = self.solve()
        self.print_result(result)

if len(sys.argv) > 1:
    sys.stdin = open(sys.argv[1], 'r')
    print('Redirect stdin to {0}'.format(sys.argv[1]))

Solution().run()

