A. The Fair Nut and Elevator

time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output

The Fair Nut lives in ? story house. ?? people live on the ?-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 ?-th floor, but ? hasn’t been chosen yet. When a person needs to get from floor ? to floor ?, elevator follows the simple algorithm: Moves from the ?-th floor (initially it stays on the ?-th floor) to the ?-th and takes the passenger.Moves from the ?-th floor to the ?-th floor and lets out the passenger (if ? equals ?, elevator just opens and closes the doors, but still comes to the floor from the ?-th floor).Moves from the ?-th floor back to the ?-th. The elevator never transposes more than one person and always goes back to the floor ? before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the ?-th floor to the ?-th floor requires |?−?| 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 ?-th floor. Don’t forget than elevator initially stays on the ?-th floor.

Input

The first line contains one integer ? (1≤?≤100) — the number of floors.
The second line contains ? integers ?1,?2,…,?? (0≤??≤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

3 0 2 1

Output

16

Input

2
1 1

Output

4

Note

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

思路

枚举答案,在进行验算即可。

代码

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#define N 1001
using namespace std;
long long a[N],n,ans=0x7fffffff;
long long _abs(long long k)
{if(k>=0) return k;else return (0-k);
}
long long f1(long long x,long long k)
{long long ret=_abs(x-k)+k+x-2;ret*=(2*a[k]);return ret;
}
int main()
{scanf("%lld",&n);for(long long i=1;i<=n;i++) scanf("%lld",&a[i]);for(long long i=1;i<=n;i++){long long ls=0;for(long long j=1;j<=n;j++) ls+=f1(i,j);if(ls<ans) ans=ls;}printf("%lld\n",ans);return 0;
}

CodeForces 1084A The Fair Nut and Elevator 题解相关推荐

  1. Codeforces 1084A - The Fair Nut and Elevator

    Codeforces 1084A - The Fair Nut and Elevator 题解链接 https://lucien.ink 题目链接 https://codeforces.com/con ...

  2. CodeForces - 1084A The Fair Nut and Elevator 数学

    题目 The Fair Nut lives in n story house. ai people live on the i-th floor of the house. Every person ...

  3. CodeForces 1084A The Fair Nut and Elevator

    题意: 电梯要停在x层,每天早上要从x层去a层接人送到1层再回到x层的等待,每天晚上要从x层下到1层接人送到a层,再回到x层(对每层的乘客都是如此),电梯每走一层耗电1,问电梯停在那一层,每天的耗电最 ...

  4. Codeforces 1084A. The Fair Nut and Elevator

    枚举电梯最开始停的位置,需要注意的是底层是1层不是0层. 判断x和i的位置关系,如果x在下面,那么上班的时候需要先上去,回家的时候同理 #include<bits/stdc++.h> us ...

  5. CodeForces 1084D The Fair Nut and the Best Path(树形dp)

    题目描述 The Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the l ...

  6. 【CodeForces - 1084D】The Fair Nut and the Best Path (树形dp)

    题干: The Fair Nut is going to travel to the Tree Country, in which there are nn cities. Most of the l ...

  7. 【CodeForces - 1084C】The Fair Nut and String(思维,组合数学)

    题干: The Fair Nut found a string ss. The string consists of lowercase Latin letters. The Nut is a cur ...

  8. C - The Fair Nut and String

    C - The Fair Nut and String CodeForces - 1084C 给出一个序列,求符合规则的序列有多少个,规则有两种,一种是只含a,一种是两个a之间夹着b. 对于每一个a有 ...

  9. 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 题意: 在一棵树内找一条路径,使得从起点 ...

最新文章

  1. HDU 5836 Rubik's Cube BFS
  2. java.sql.SQLException: Lock wait timeout exceeded --转
  3. 使用子查询进行编号重排的处理示例.sql
  4. 魅族android 版本 6.0下载,flyme6.0内测版
  5. java中抛出异常快捷键_idea中处理异常的快捷键
  6. 平平无奇的项目「GitHub 热点速览 v.22.10」
  7. TOPSIS优劣解距离法
  8. java zoom,进口javazoom不能得到解决
  9. html实现个人空间主页(附源码)
  10. 【PCAN医疗应用系列】CAN总线技术在实现实时荧光定量基因扩展(PCR)仪控制系统上的应用(2)
  11. android 开门动画,Android之高仿微信“开门动画”(六)
  12. HDR高动态范围成像
  13. Falsy Bouncer 过滤数组假值
  14. FlashFXP 便携版,U盘版,真正绿色
  15. pyecharts绘制省级地图(Map地图、Geo动态涟漪散点图、Geo动态轨迹图)
  16. 刷新-读书笔记2(4-7章)
  17. 系统入门(1):安卓系统bootloader模式是什么?如何进入bootloader
  18. java练习题-显示人的年龄和姓名
  19. 英国小学生记忆英语单词的方法
  20. 达梦数据库DM8-DM管理工具介绍和简单使用

热门文章

  1. UG/NX二次开发(C#) 创建体的最小包容块
  2. 接口报错500是什么意思_http500什么意思
  3. 10本书给你计算机大师思维
  4. [JAVA毕业设计]html5大众汽车网站源码获取和系统演示
  5. 上海迪士尼将首次推出上海迪士尼乐园尊长季卡,专为65周岁及以上的游客设计...
  6. 上海迪士尼持续火爆,原来是大数据背后撑腰
  7. BBB学习(六):Windows电脑通信调试(2):BBB连接网络
  8. Oracle游标超出最大值
  9. 2018最新iOS端界面UI设计规范整理
  10. h5可拖动悬浮按钮_手机端H5悬浮按钮怎么实现的呢?