404509: GYM101522 A Ambiguous Dates

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Ambiguous Datestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are two popular formats for representing a date: day/month/year or month/day/year. For example, today can be represented as 15/8/2017 or 8/15/2017.

Sometimes (like on today), using one way or another should pose no confusion — it is immediately understood that the date is the 15th of August. On other days, however, the two representations may be interpreted as two different valid dates. For example, the 7th of August may be misinterpreted as the 8th of July, since both can be represented as 7/8/2017 (or 8/7/2017).

We say a date (D, M, Y) is ambiguous if D/M/Y and M/D/Y, when both interpreted in the day/month/year format, are different valid dates. For example, (7, 8, 2017) and (8, 7, 2017) are ambiguous, while (15, 8, 2017) and (10, 10, 2017) are not.

The total number of ambiguous dates in the Gregorian calendar system on any given year is equal to 12 × 11 = 132.

Now, suppose that in a hypothetical calendar system, there are M months, where the i-th month has D[i] days, numbered from 1 to D[i]. Assume that there are no leap years.

You are to carry out a calendar reform, by shuffling the array D[], and your target is to minimize the total number of ambiguous dates in a calendar year. Specifically, you want to find a permutation p[1], p[2], ..., p[M] of integers 1, 2, ..., M, such that the new calendar system, where the i-th month has D[p[i]] days, has the minimal number of ambiguous dates. Output that minimal number.

Input

The first line of input consists of a single integer M, the number of months in the hypothetical calendar system.

The second line of input consists of M integers D[1], D[2], ..., D[M], the original number of days in the i-th month.

For all test cases, 1 ≤ M ≤ 105, 1 ≤ D[i] ≤ 105.

Output

Output a single integer, the minimal number of ambiguous dates after the calendar reform.

ExamplesInput
12
31 28 31 30 31 30 31 31 30 31 30 31
Output
132
Input
3
5 1 1
Output
0

加入题单

上一题 下一题 算法标签: