欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1084A.The Fair Nut and Elevator
The Fair Nut and Elevator
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 () — the number of floors.
The second line contains integers () — the number of people on each floor.
Output
In a single line, print the answer to the problem — the minimum number of electricity units.
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 units of electricity per day ( to get down and to get up), and one person from the third would spend units of electricity per day ( to get down and to get up). .
In the second example, the answer can be achieved by choosing the first floor as the -th floor.
Samples
3
0 2 1
16
2
1 1
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |