Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elementsai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn.

Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input.

The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).

Output

Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.

Sample test(s)
input
5
1 2 3 4 5

output
5

input
4
1 2 2 1

output
3

Note

In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.

In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=200000+100;
ll a[maxn];
int main()
{int n,i,j,t;ll ans;ans=0;cin>>n;for(i=1;i<=n;i++) cin>>a[i];a[0]=0;for(i=1;i<=n;i++) {t=a[i]-a[i-1];if(t<0) t=-t;ans+=t;}cout<<ans<<endl;return 0;
}

cf B. Wilbur and Array相关推荐

  1. cf596B. Wilbur and Array

    B. Wilbur and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Wilbur and Array

    Wilbur and Array Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...

  3. CodeForces 596B Wilbur and Array 贪心

    给出原始{ai}={0},{bi}.每次修改{ai..n}+1或-1,求最小操作次数使{ai}=={bi}. 累计相邻两数差即可. 因为差最大10^9,数字有2*10^5,要long long. #i ...

  4. B. Wilbur and Array

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. CodeForces 596 B Wilbur and Array

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  6. CF 295A - Greg and Array 差分數列

    一维的差分数列如下定义: 假设原数组为a[1]...a[n],a[0] = 0 差分数列数组为d[1]...d[n] 则d[i] = a[i]-a[i-1] (d数组初始化) 題目: 給出原始數列a[ ...

  7. ★☆★cf D. Petya and Array

    http://codeforces.com/problemset/problem/1042/D 抽象成一个问题:一边增加数组长度,增加之后再随机找小于某阈值的数的个数. 树状数组,离散化,模拟运行一遍 ...

  8. CodeForces 596B Wilbur and Array

    简单题,一个一个操作,最后就是答案. #include<cstdio> #include<cstring> #include<cmath> #include< ...

  9. [cf] Codeforces 817D Imbalanced Array 单调栈

    前言 传送门 : 优质题解传送门 : wls题目传送门 : 思路 使用单调栈维护当前节点 是最大值的时候的区间 以及当前节点是最小值时候的区间 然后统计计数即可 而求区间最大最小值可以使用单调栈处理 ...

最新文章

  1. 第二章 数据类型、运算符与表达式
  2. 链表题目总结(第一篇)
  3. html multiply属性,NonCommutativeMultiply
  4. Mahout的推荐系统
  5. HDLBits答案(11)_Verilog计数器
  6. (三)深入浅出TCPIP之再识TCP,理解TCP四次挥手(上)
  7. Asp.Net在SqlServer中的图片存取
  8. 10010序列检测器的三段式状态机实现(verilog)
  9. 2ask matlab仿真,2ask调制解调系统仿真实验程序
  10. 基于unity+vuforia的VR二级齿轮减速器动画分解
  11. linux下声卡配置文件,Linux如何设置声卡
  12. 克利夫顿优势识别器 Clifton Strengths
  13. 架构思维成长系列教程(八)- 电商供应链系统架构设计
  14. CSS 列表样式 (ul)
  15. SuperMap地图发布
  16. 用最科学的方法展示最形象的图表——前端数据可视化实践
  17. VSCode的撤回与取消撤回
  18. PTA 公路村村通
  19. Just for fun----zjfc 并查集操作
  20. AlarmManager用法的注意事项

热门文章

  1. redis 在32位系统安装以及使用
  2. xdos攻击ac实验环境
  3. 华硕飞行堡垒安装ubuntu一系列坑
  4. 硕士毕业,两年北漂算法工程打工生活【上】
  5. 几种常用交叉验证(cross validation)方式的比较
  6. HIT-哈工大数据结构-作业5(C++)
  7. 一个用在手机上的简单js拖拽效果
  8. 自己动手做Arduino玩具(三)
  9. 1.4、云计算HCIA虚拟化存储基础知识
  10. SEPIC 单端初级电感转换器 稳压器 -- Zeta 转换器