#P5634. 数码排序【加强版】

数码排序【加强版】

Description

While escaping, some digital beings also escaped. They are making a fuss and asking Xiao L to help sort them.

The digital beings in the virtual world are invisible.

Right now, Xiao L only knows selection sort, insertion sort, bubble sort, and merge sort.

So Xiao L wants to ask: in the worst case, what is the minimum number of comparisons needed to make the sequence sorted?


Template code for sorting

Input Format

The input has only one line: a positive integer nn, the length of the sequence.

Output Format

Output the minimum number of comparisons. Take the answer modulo 100000007100000007.

4
5
5
8

Hint

  • Sample 11 explanation.

For a sequence of length 44, merge sort splits it into 22 groups, with 22 elements in each group. The 22 elements in each group are compared once. During merging, the worst-case number of comparisons is 33, so the total is 3+1+1=53 + 1 + 1 = 5.

  • Constraints

For 10%10\% of the testdata, n1018n \leq 10^{18}.

For 20%20\% of the testdata, n10100n \leq 10^{100}.

For 50%50\% of the testdata, n101000n \leq 10^{1000}.

For 80%80\% of the testdata, n1010000n \leq 10^{10000}.

For 100%100\% of the testdata, n10100000n \leq 10^{100000}.

Please pay attention to the time limit.

Translated by ChatGPT 5