A. Ambiguous Dates

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.

Example

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

代码:

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+;
int a[N];
int main(){
int n;
ll ans;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a++n);
ans=;
for(int i=;i<=n;i++){
if(a[i]>n){if(n-i>)ans+=n-i;}
if(a[i]<n){if(a[i]-i>)ans+=a[i]-i;}
if(a[i]==n){if(n-i>)ans+=n-i;}
}
ans*=;
printf("%lld\n",ans);
}
return ;
}

最新文章

  1. dede教程之后台登录是自动跳出解决方法
  2. git 10.8
  3. Scheme中一些函数在C++里面的实现与吐槽
  4. linux(centos)搭建svn
  5. css3 -&amp;gt; 多栏布局
  6. 必胜宅急送Web app设计背后的思考
  7. 解决xp下无法通过windows installer服务安装此安装程序包。您必须安装带有更新版本Wi
  8. c语言10个经典小程序
  9. [TroubleShooting] The remote copy of database xx has not been rolled forward to a point in time
  10. Voilin 之 握弓
  11. elastalert基于微信公众号报警
  12. Ajax中的JSON格式与php传输过程的浅析
  13. hdu 2209 bfs+状压
  14. StopAllSounds
  15. MFC窗口风格 WS_style/WS_EX_style
  16. 网易云和QQ音乐api
  17. 检查手机是否安装外置SD卡
  18. php与java通用AES加密解密算法
  19. Koa快速入门教程(一)
  20. IPV6修复工具

热门文章

  1. linux命令(shell)
  2. 聚簇(或者叫做聚集,cluster)索引和非聚簇索引
  3. Fiddler 抓包https配置 提示creation of the root certificate was not successful 证书安装不成功
  4. jQuery知识盲点
  5. thinkphp 3.1.3 redis 只能读取 无法写入的问题
  6. MySQL一对一:一对多:多对多: 实例!!!!
  7. chromedriver与chrome版本映射列表
  8. CSS样式表学习
  9. SourceTree管理工具的一些使用总结
  10. js 对象的值传递