time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The Fair Nut lives in nn story house. aiai people live on the ii-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening.

It was decided that elevator, when it is not used, will stay on the xx-th floor, but xx hasn't been chosen yet. When a person needs to get from floor aa to floor bb, elevator follows the simple algorithm:

  • Moves from the xx-th floor (initially it stays on the xx-th floor) to the aa-th and takes the passenger.
  • Moves from the aa-th floor to the bb-th floor and lets out the passenger (if aa equals bb, elevator just opens and closes the doors, but stillcomes to the floor from the xx-th floor).
  • Moves from the bb-th floor back to the xx-th.

The elevator never transposes more than one person and always goes back to the floor xx before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the aa-th floor to the bb-th floor requires |a−b||a−b|units of electricity.

Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the xx-th floor. Don't forget than elevator initially stays on the xx-th floor.

Input

The first line contains one integer nn (1≤n≤1001≤n≤100) — the number of floors.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1000≤ai≤100) — the number of people on each floor.

Output

In a single line, print the answer to the problem — the minimum number of electricity units.

Examples

input

Copy

3
0 2 1

output

Copy

16

input

Copy

2
1 1

output

Copy

4

Note

In the first example, the answer can be achieved by choosing the second floor as the xx-th floor. Each person from the second floor (there are two of them) would spend 44 units of electricity per day (22 to get down and 22 to get up), and one person from the third would spend 88units of electricity per day (44 to get down and 44 to get up). 4⋅2+8⋅1=164⋅2+8⋅1=16.

In the second example, the answer can be achieved by choosing the first floor as the xx-th floor.

题解:暴力枚举上下楼的过程即可

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; int main()
{
int n;
cin>>n;
int a[105];
for(int t=1;t<=n;t++)
{
scanf("%d",&a[t]);
}
long long int s;
long long int minn=0x3f3f3f;
for(int t=1;t<=n;t++)
{
s=0;
for(int j=1;j<=n;j++)
{
s+=(abs(j-t)+abs(t-1)+abs(j-1))*2*a[j];
}
minn=min(minn,s);
}
cout<<minn<<endl;
return 0;
}

A. The Fair Nut and Elevator(暴力)的更多相关文章

  1. A. The Fair Nut and Elevator (Codeforces Round #526 (Div. 2))

    A. The Fair Nut and Elevator 好笨啊QAQ. 暴力枚举的题,连分类都不用. 从电梯初始位置到第一层.人到第一层.间隔的层数,往返路程. #include <bits/ ...

  2. CF1083E The Fair Nut and Rectangles

    CF1083E The Fair Nut and Rectangles 给定 \(n\) 个平面直角坐标系中左下角为坐标原点,右上角为 \((x_i,\ y_i)\) 的互不包含的矩形,每一个矩形拥有 ...

  3. CF 1083 B. The Fair Nut and Strings

    B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析:  建出trie树,给定的两个字符串就 ...

  4. CF 1083 A. The Fair Nut and the Best Path

    A. The Fair Nut and the Best Path https://codeforces.com/contest/1083/problem/A 题意: 在一棵树内找一条路径,使得从起点 ...

  5. CF1083A The Fair Nut and the Best Path

    CF1083A The Fair Nut and the Best Path 先把边权搞成点权(其实也可以不用),那么就是询问树上路径的最大权值. 任意时刻权值非负的限制可以不用管,因为若走路径 \( ...

  6. Codeforces Round #526 (Div. 2) E. The Fair Nut and Strings

    E. The Fair Nut and Strings 题目链接:https://codeforces.com/contest/1084/problem/E 题意: 输入n,k,k代表一共有长度为n的 ...

  7. Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path

    D. The Fair Nut and the Best Path 题目链接:https://codeforces.com/contest/1084/problem/D 题意: 给出一棵树,走不重复的 ...

  8. Codeforces Round #526 (Div. 2) C. The Fair Nut and String

    C. The Fair Nut and String 题目链接:https://codeforces.com/contest/1084/problem/C 题意: 给出一个字符串,找出都为a的子序列( ...

  9. C. The Fair Nut and String 递推分段形dp

    C. The Fair Nut and String 递推分段形dp 题意 给出一个字符串选择一个序列\({p_1,p_2...p_k}\)使得 对于任意一个\(p_i\) , \(s[p_i]==a ...

随机推荐

  1. POJ-2564 01背包问题

    #include"cstdio" #include"cstring" #include"algorithm" using namespace ...

  2. [BZOJ1396&2865]识别子串

    bzoj1396 bzoj2865 dbzoj1396 dbzoj2865 题面 XX在进行字符串研究的时候,遇到了一个十分棘手的问题. 在这个问题中,给定一个字符串\(S\),与一个整数\(K\), ...

  3. poj3252 Round Numbers[数位DP]

    地址 拆成2进制位做dp记搜就行了,带一下前导0,将0和1的个数带到状态里面,每种0和1的个数讨论一下,累加即可. WA记录:line29. #include<iostream> #inc ...

  4. 构建嵌入式小型Linux系统

    构建嵌入式小型Linux系统 摘要:用buildroot构建x86的交叉编译工具链:裁减linux内核,尽可能做到最小:手工构建根文件系统:安装qemu虚拟机,仿真新配置的Linux系统:为新配置的L ...

  5. app专项测试(稳定性测试、安全性测试)

    https://blog.csdn.net/xiaomaoxiao336368/article/details/84887948

  6. hashCode之二--Java:重写equals()和hashCode()

    以下内容总结自<Effective Java>. 1.何时需要重写equals() 当一个类有自己特有的“逻辑相等”概念(不同于对象身份的概念). 2.设计equals() [1]使用in ...

  7. web攻击之三:SQL注入攻击的种类和防范手段

    观察近来的一些安全事件及其后果,安全专家们已经得到一个结论,这些威胁主要是通过SQL注入造成的.虽然前面有许多文章讨论了SQL注入,但今天所讨论的内容也许可帮助你检查自己的服务器,并采取相应防范措施. ...

  8. modbus读输入状态与读线圈状态的区别?

    01 读线圈状态 描述 读从机离散量输出口的 ON/OFF 状态,不支持广播.附录B列出由不同控制器型号支持最大的参数清单. 查询 查询信息规定了要读的起始线圈和线圈量,线圈的起始地址为零,1-16个 ...

  9. 关于Confusion Matrix

    from sklearn.metrics import confusion_matrixy_true = [2, 0, 2, 2, 0, 1]y_pred = [0, 0, 2, 2, 0, 2]pr ...

  10. web实现本地缓存的方法

    Cookie(或者Cookies) 指一般网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密). cookie一般通过http请求中在头部一起发送到服务器端.一条c ...