Under construction

Still being built. Things may change

Call forwarding chaos

Interview

Time limit1sMemory limit1024 MB

Summary
Given each phone's forwarding target, change the fewest settings so that every phone's call ends in a loop of two or more phones, and print the new settings.
Level

Easy3 of 10

Topics
Graph, Implementation
Solved
No attempts yet

Problem

Dohun's unit has phones with a feature called call forwarding. Call forwarding sends an incoming call on one phone to another phone instead. For example, if phone AA forwards to phone BB, a call to phone AA rings phone BB. Each phone can forward to at most one other phone.

This feature has a serious flaw. When forwarding settings form a loop, some phones go dead. For example, phone AA forwards to phone BB, phone BB forwards to phone CC, and phone CC forwards to phone AA. Then a call to any of the three phones waits forever, and all three phones go dead.

Impressed by this, Dohun plans to change the forwarding settings of some phones so that every phone in the unit goes dead. The unit has NN phones numbered 11 to NN. Phone ii currently forwards to phone aia_i. If ai=ia_i = i, phone ii has no forwarding.

Changing too many settings would get Dohun caught by an officer, so he must change as few phones as possible. Find the minimum number of phones whose settings must change, along with the new settings. If several answers exist, any one is accepted. It is always possible to make every phone go dead.

Input

The first line contains NN, the number of phones. (2≤N≤100 0002\leq N\leq 100\,000)

The second line contains NN integers a1,⋯ ,aNa_1, \cdots, a_N separated by spaces. (1≤ai≤N1\leq a_i\leq N)

If ai=ia_i = i, phone ii has no call forwarding.

Output

The first line contains the minimum number of phones whose forwarding settings must change so that every phone goes dead.

The second line contains NN integers b1,⋯ ,bNb_1, \cdots, b_N, the forwarding settings after the changes. If several answers exist, print any of them.

Examples3

  1. Example 1

    Input
    3
    1 2 3
    
    Expected output
    3
    2 3 1
    
  2. Example 2

    Input
    5
    2 1 5 3 4
    
    Expected output
    0
    2 1 5 3 4
    
  3. Example 3

    Input
    4
    4 4 4 4
    
    Expected output
    1
    4 4 4 3