Salem and Sticks

Salem gave you nn sticks with integer positive lengths a1,a2,…,ana1,a2,…,an.

For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from aa to bb is |a−b||a−b|, where |x||x| means the absolute value of xx.

A stick length aiai is called almost good for some integer tt if |ai−t|≤1|ai−t|≤1.

Salem asks you to change the lengths of some sticks (possibly all or none), such that all sticks' lengths are almost good for some positive integer tt and the total cost of changing is minimum possible. The value of tt is not fixed in advance and you can choose it as any positive integer.

As an answer, print the value of tt and the minimum cost. If there are multiple optimal choices for tt, print any of them.

Input

The first line contains a single integer nn (1≤n≤10001≤n≤1000) — the number of sticks.

The second line contains nn integers aiai (1≤ai≤1001≤ai≤100) — the lengths of the sticks.

Output

Print the value of tt and the minimum possible cost. If there are multiple optimal choices for tt, print any of them.

Examples

input

3
10 1 4

output

3 7

input

5
1 1 2 2 3

output

2 0

Note

In the first example, we can change 11 into 22 and 1010 into 44 with cost |1−2|+|10−4|=1+6=7|1−2|+|10−4|=1+6=7 and the resulting lengths [2,4,4][2,4,4]are almost good for t=3t=3.

In the second example, the sticks lengths are already almost good for t=2t=2, so we don't have to do anything.

 题目大意:将棒的长度从a更改为b的成本为|a−b|,要求求出用最小的花费使所有的棒子一样长,每一根棒子的长度小于100,所有暴力就好了

#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long lint;
int main()
{
    int n;
    int i;
    int j;
    while(cin>>n){
        int a[n];
        int maxn=-1;
        int ans=999999;
        int s=0;
        int flag=0;
        for(i=0;i<n;++i){
            cin>>a[i];
            if(a[i]>maxn)
                maxn=a[i];
        }
        for(i=1;i<=maxn;++i){
            s=0;
            for(j=0;j<n;++j){
                if(a[j]>i+1){
                    s=s+a[j]-(i+1);
                }
                else if(a[j]<i-1){
                    s=s+i-1-a[j];
                }
            }
            if(ans>s){
                ans=s;
                flag=i;
            }
            if(s==0)
                break;
        }
        cout<<flag<<" "<<ans<<endl;
    }
    return 0;
}

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值