A tree is an undirected connected graph without cycles.

Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is considered its own parent).

<image> For this rooted tree the array p is [2, 3, 3, 2].

Given a sequence p1, p2, ..., pn, one is able to restore a tree:

  1. There must be exactly one index r that pr = r. A vertex r is a root of the tree. 
  2. For all other n - 1 vertices i, there is an edge between vertex i and vertex pi. 



A sequence p1, p2, ..., pn is called valid if the described procedure generates some (any) rooted tree. For example, for n = 3 sequences (1,2,2), (2,3,1) and (2,1,3) are not valid.

You are given a sequence a1, a2, ..., an, not necessarily valid. Your task is to change the minimum number of elements, in order to get a valid sequence. Print the minimum number of changes and an example of a valid sequence after that number of changes. If there are many valid sequences achievable in the minimum number of changes, print any of them.

Input

The first line of the input contains an integer n (2 ≤ n ≤ 200 000) — the number of vertices in the tree.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n).

Output

In the first line print the minimum number of elements to change, in order to get a valid sequence.

In the second line, print any valid sequence possible to get from (a1, a2, ..., an) in the minimum number of changes. If there are many such sequences, any of them will be accepted.

Examples

Input

4
2 3 3 4


Output

1
2 3 4 4 


Input

5
3 2 2 5 3


Output

0
3 2 2 5 3 


Input

8
2 3 5 4 1 6 6 7


Output

2
2 3 7 8 1 6 6 7

Note

In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4 = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On both drawings, roots are painted red.

<image>

In the second sample, the given sequence is already valid.

Difficulty: MEDIUM_HARD
Tags: Graph algorithms

Graph traversal

Constructive algorithms

Tree algorithms

Spanning trees

Starter code:

Solutions:
input()
A = list(map(int, input().split(' ')))
root = -1
for (i, a) in enumerate(A):
	if i == a - 1:
		root = i
		break
v = [False] * len(A)
if root > -1:
	v[root] = True
ans = 0
for (i, a) in enumerate(A):
	if v[i]:
		continue
	v[i] = True
	l = [i]
	a -= 1
	while not v[a]:
		l.append(a)
		v[a] = True
		a = A[a] - 1
	if a in l:
		if root == -1:
			A[a] = a + 1
			root = a
			ans += 1
		else:
			A[a] = root + 1
			ans += 1
print(ans)
print(' '.join(map(str, A)))


import sys
input = sys.stdin.readline
n = int(input())
lis = [0, *map(int, input().split())]
v = [0] * (n + 1)
cycles = set()
roots = set()
for i in range(1, n + 1):
	if v[i] == 0:
		node = i
		while v[node] == 0:
			v[node] = 1
			node = lis[node]
		if v[node] == 2:
			continue
		start = node
		ignore = 0
		l = 1
		while lis[node] != start:
			if v[node] == 2:
				ignore = 1
				break
			v[node] = 2
			node = lis[node]
			l += 1
		if ignore:
			continue
		v[node] = 2
		if l == 1:
			roots.add(node)
		else:
			cycles.add(node)
ans = 0
if roots:
	base = roots.pop()
	for i in roots:
		lis[i] = base
		ans += 1
	for i in cycles:
		lis[i] = base
		ans += 1
elif cycles:
	base = cycles.pop()
	cycles.add(base)
	for i in roots:
		lis[i] = base
		ans += 1
	for i in cycles:
		lis[i] = base
		ans += 1
print(ans)
print(*lis[1:])


n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
	arr[i] -= 1
ans = []

def getRoot(lst):
	for i in lst:
		if arr[i] == i:
			return i
	s = set()
	st = lst[0]
	while st not in s:
		s.add(st)
		st = arr[st]
	return st
root = getRoot(list(range(n)))

def fixRoot(r):
	if arr[r] != root:
		arr[r] = root
		ans.append(1)
fixRoot(root)
adj = [[] for _ in range(n)]
for i in range(n):
	adj[arr[i]].append(i)
	adj[i].append(arr[i])
vis = [0] * n

def BFS(v):
	(seen, vis[v], cur) = ([v], 1, 0)
	while cur < len(seen):
		(v, cur) = (seen[cur], cur + 1)
		for nv in adj[v]:
			if vis[nv] == 0:
				seen.append(nv)
				vis[nv] = 1
	return seen
comp = [BFS(i) for i in range(n) if vis[i] == 0]
for c in comp:
	r = getRoot(c)
	fixRoot(r)
print(sum(ans))
for i in range(n):
	arr[i] += 1
print(*arr)


root = -1

def find(i, time):
	parent[i] = time
	while not parent[aa[i]]:
		i = aa[i]
		parent[i] = time
	if parent[aa[i]] == time:
		global root
		if root == -1:
			root = i
		if aa[i] != root:
			aa[i] = root
			global ans
			ans += 1
n = int(input())
aa = [0] + [int(i) for i in input().split()]
parent = [0] * (n + 1)
ans = 0
time = 0
for i in range(1, n + 1):
	if aa[i] == i:
		root = i
		break
for i in range(1, n + 1):
	if not parent[i]:
		time += 1
		find(i, time)
print(ans)
print(*aa[1:])


n = int(input())
par = [int(x) - 1 for x in input().split()]
assert len(par) == n
changes = 0
root = -1
for (i, p) in enumerate(par):
	if i == p:
		root = i
		break
seen = [-1 for _ in range(n)]
for x in range(n):
	if seen[x] >= 0:
		continue
	seen[x] = x
	cur = x
	while par[cur] != cur:
		if seen[par[cur]] >= 0 and seen[par[cur]] < x:
			break
		if seen[par[cur]] == x:
			changes += 1
			if root == -1:
				par[cur] = cur
				root = cur
			else:
				par[cur] = root
			break
		cur = par[cur]
		seen[cur] = x
for (i, p) in enumerate(par):
	if i == p and i != root:
		par[i] = root
		changes += 1
print(changes)
print(' '.join([str(p + 1) for p in par]))


from collections import deque

def Padre(x, P):
	while x != P[x]:
		x = P[x]
	return x

def Solucion():
	P = [None] * n
	for i in range(0, n):
		P[i] = i
	ciclosC = 0
	ciclos = deque([])
	root = []
	i = 0
	while i < n:
		padre = Padre(A[i], P)
		if padre == i:
			if not root and i == A[i]:
				root = [i, A[i]]
			else:
				ciclos.append([i, A[i]])
				ciclosC += 1
		else:
			P[i] = A[i]
		i += 1
	print(str(ciclosC))
	if ciclosC:
		i = 0
		if not root:
			root = ciclos.popleft()
			i = 1
		while ciclos:
			ciclo = ciclos.popleft()
			P[ciclo[0]] = root[0]
	PC = [x + 1 for x in P]
	print(*PC, sep=' ')

def DFS(x, color, padre, ciclos, adyacentes, raiz):
	color[x] = 1
	for y in adyacentes[x]:
		if color[y] == 0:
			DFS(y, color, padre, ciclos, adyacentes, raiz)
			padre[y] = x
		elif color[y] == 2:
			padre[y] = x
		elif y == x and (not raiz):
			raiz = x
		else:
			ciclos.append([x, y])
	color[x] = 2
n = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))
Solucion()


from collections import deque

def Padre(x, padre):
	while x != padre[x]:
		x = padre[x]
	return x

def FixATree():
	n = int(input())
	A = list(map(lambda x: int(x) - 1, input().split()))
	padre = [x for x in range(0, n)]
	ciclosC = 0
	ciclos = deque([])
	root = []
	for i in range(0, n):
		p = Padre(A[i], padre)
		if p == i:
			if not root and i == A[i]:
				root = [i, A[i]]
			else:
				ciclos.append([i, A[i]])
				ciclosC += 1
		else:
			padre[i] = A[i]
	print(str(ciclosC))
	if ciclosC:
		i = 0
		if not root:
			root = ciclos.popleft()
			i = 1
		while ciclos:
			ciclo = ciclos.popleft()
			padre[ciclo[0]] = root[0]
	PC = [x + 1 for x in padre]
	print(*PC, sep=' ')
FixATree()


n = int(input())
parents = [None] + list(map(int, input().split()))
visited = [None] * len(parents)
candidates = set()
hot = None
for node in range(1, n + 1):
	if visited[node]:
		continue
	run = node
	visited[node] = run
	while parents[node] != node and (not visited[parents[node]]):
		node = parents[node]
		visited[node] = run
	if visited[parents[node]] == run:
		candidates.add(node)
	if parents[node] == node:
		hot = node
if hot:
	root = hot
	candidates.remove(hot)
else:
	root = candidates.pop()
	candidates.add(root)
print(len(candidates))
print(' '.join(map(str, (p if node not in candidates else root for (node, p) in list(enumerate(parents))[1:]))))


n = int(input())
arr = list(map(int, input().split(' ')))
root = -1
for (i, a) in enumerate(arr):
	if i == a - 1:
		root = i
		break
v = [False] * len(arr)
if root > -1:
	v[root] = True
ret = 0
for (i, a) in enumerate(arr):
	if v[i]:
		continue
	v[i] = True
	curl = [i]
	a -= 1
	while not v[a]:
		curl.append(a)
		v[a] = True
		a = arr[a] - 1
	if a in curl:
		if root == -1:
			arr[a] = a + 1
			root = a
			ret += 1
		else:
			arr[a] = root + 1
			ret += 1
print(ret)
print(' '.join(map(str, arr)))


class DSU(object):

	def __init__(self, n):
		self.p = list(range(n))
		self.rk = [0] * n

	def find(self, u):
		while u != self.p[u]:
			u = self.p[u]
		return 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]
n = int(input())
p = list(map(int, input().split()))
dsu = DSU(n)
s = None
for u in range(n):
	p[u] -= 1
	if p[u] == u:
		s = u
for u in range(n):
	dsu.unite(u, p[u])
ans = 0
rt = [None] * n
vis = [False] * n
for u in range(n):
	if dsu.find(u) != u:
		continue
	v = u
	while not vis[v]:
		vis[v] = True
		v = p[v]
	rt[u] = v
	if p[v] != v:
		p[v] = v
		if s is None:
			ans += 1
			s = v
for u in range(n):
	if u != dsu.find(s) and u == dsu.find(u):
		p[rt[u]] = s
		ans += 1
print(ans)
for u in range(n):
	p[u] += 1
print(*p)


tree_size = int(input())
parents = [int(x) - 1 for x in input().split(' ')]
num_changes = 0
root = tree_size
for (node, parent) in enumerate(parents):
	if parent == node:
		root = node
		break
visited = set()
finished = set()
visited.add(root)
finished.add(root)
stack = []
fringe = []
for node in range(len(parents)):
	if node not in visited:
		fringe.append(node)
		while fringe:
			cur = fringe.pop()
			visited.add(cur)
			stack.append(cur)
			if parents[cur] not in finished:
				if parents[cur] in visited:
					parents[cur] = root
					num_changes += 1
				else:
					fringe.append(parents[cur])
		while stack:
			finished.add(stack.pop())
if root == tree_size:
	new_root = None
	for (node, parent) in enumerate(parents):
		if parent == root:
			if new_root is None:
				new_root = node
			parents[node] = new_root
for i in range(len(parents)):
	parents[i] += 1
print(num_changes)
print(*parents)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
from functools import lru_cache

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
N = int(input())
A = alele()
root = -1
vis = [False] * N
for i in range(N):
	if i == A[i] - 1:
		root = i
		vis[i] = True
		break
count = 0
for i in range(N):
	if not vis[i]:
		vis[i] = True
		x = A[i] - 1
		temp = [i]
		while not vis[x]:
			temp.append(x)
			vis[x] = True
			x = A[x] - 1
		if x in temp:
			if root == -1:
				root = x
			A[x] = root + 1
			count += 1
print(count)
print(*A)


n = int(input())
a = list(map(int, input().split()))
par = []
for i in range(n):
	if a[i] == i + 1:
		par.append(i)
v = [False for i in range(n)]
for i in par:
	v[i] = True
ccl = []
for i in range(n):
	if v[i]:
		continue
	s = [i]
	v[i] = True
	p = set(s)
	t = True
	while s and t:
		x = s.pop()
		j = a[x] - 1
		if j in p:
			ccl.append(j)
			t = False
		else:
			s.append(j)
			p.add(j)
		if v[j]:
			t = False
		else:
			v[j] = True
if len(par) == 0:
	print(len(ccl))
	c = ccl[0]
	a[c] = c + 1
	for i in range(1, len(ccl)):
		a[ccl[i]] = c + 1
	print(*a)
else:
	print(len(ccl) + len(par) - 1)
	c = par[0]
	for i in range(1, len(par)):
		a[par[i]] = c + 1
	for i in range(len(ccl)):
		a[ccl[i]] = c + 1
	print(*a)