Kaz's Party

시간 제한2초메모리 제한2048 MB

요약
n명의 친구가 있을 때, 모든 사람이 원하는 음료를 받을 때까지 교환 과정이 걸리는 기대 라운드 수를 최대로 만드는 순열을 찾아 그 값을 출력한다.
난이도

어려움10점 중 8점

유형
확률, 조합론, 수학, 그리디
정답자
아직 제출이 없습니다

문제

Kaz is inviting nn of his friends over for a party! He has currently prepared the cocktails for them (each friend has ordered a different drink), with friend ii having a preference for cocktail ii.

However, Kaz is looking to pull a prank. When handing out drinks if he hands out a drink to the wrong person, he knows the following round of an 'exchange process' will occur: all partygoers who do not have their desired drinks will leave their drinks on a table. All such drinks will be shuffled and handed back in a completely random order to those still in the exchange process. Any participants who receive their desired drink will leave to enjoy the party, while those still with the wrong drink will shuffle again.

To maximize the humor of his prank, Kaz wants the exchange process to take the maximum expected number of rounds. Help Kaz find an assignment of drinks that will maximize this value.

입력

The input consists of a single integer nn (1≤n≤1,0001 \leq n \leq 1\\,000) --- the number of friends invited to the party.

출력

On the first line, output a single real number RR --- the maximum expected number of rounds.

On the second line, output nn distinct integers p_1,p_2,⋯ ,p_np\_1, p\_2, \cdots, p\_n (1≤p_i≤n1 \leq p\_i \leq n) --- the assignment of the drinks. Here, drink p_ip\_i will be handed to friend ii.

Your answer will be accepted if the output satisfies the following conditions.

  • The value of RR differs from the actual answer by at most 10−910^{-9} absolute or relative error.
  • The value of RR differs from the expected number of rounds given the permutation pp by at most 10−910^{-9} absolute or relative error.

예제1

  1. 예제 1

    입력
    2
    
    예상 출력
    2.0
    2 1