Wilbur the pig is tinkering with arrays again. He has the array a_1, a_2, ..., a_{n} initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements a_{i}, a_{i} + 1, ... , a_{n} or subtract 1 from all elements a_{i}, a_{i} + 1, ..., a_{n}. His goal is to end up with the array b_1, b_2, ..., b_{n}. 

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 a_{i}. Initially a_{i} = 0 for every position i, so this array is not given in the input.

The second line of the input contains n integers b_1, b_2, ..., b_{n} ( - 10^9 ≤ b_{i} ≤ 10^9).


-----Output-----

Print the minimum number of steps that Wilbur needs to make in order to achieve a_{i} = b_{i} for all i.


-----Examples-----
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.

Source: codeforces | Difficulty: EASY
Tags: Implementation

Greedy algorithms


Solutions:
n = int(input())
l = list(map(int, input().split()))
p = 0
k = 0
for i in range(n):
	k = k + abs(l[i] - p)
	p = l[i]
print(k)


n = int(input())
ary = [int(_) for _ in input().split()]
now = 0
ans = 0
for i in range(n):
	ans += abs(ary[i] - now)
	now += ary[i] - now
print(ans)


n = int(input())
result = 0
offset = 0
for x in map(int, input().split()):
	need = x - offset
	result += abs(need)
	offset += need
print(result)


n = int(input())
x = list(map(int, input().split()))
cnt = abs(x[0])
for i in range(1, n):
	cnt += max(x[i], x[i - 1]) - min(x[i], x[i - 1])
print(cnt)


n = int(input())
a = [int(i) for i in input().split()]
count = abs(a[0])
for i in range(1, len(a)):
	count = count + abs(a[i] - a[i - 1])
print(count)


n = int(input())
arr = list(map(int, input().split()))
count = 0
num = 0
for x in arr:
	if num != x:
		if num > x:
			sub = abs(num - x)
			count += sub
			num -= sub
		if num < x:
			add = abs(num - x)
			count += add
			num += add
print(count)


n = int(input())
a = list(map(int, input().split()))
step = abs(a[0])
cu = a[0]
for i in a[1:]:
	step += abs(i - cu)
	cu += i - cu
print(step)


x = int(input())
z = list(map(int, input().split()))
ans = abs(z[0])
for i in range(1, x):
	ans += abs(z[i] - z[i - 1])
print(ans)


n = int(input())
li = list(map(int, input().split()))
st = False
res = 0
for i in range(n - 1):
	if i == 0:
		res += abs(li[i])
	res += abs(li[i] - li[i + 1])
print(res)


bSize = int(input())
b = [int(x) for x in input().split()]
steps = 0
lastB = 0
for i in range(bSize):
	steps += abs(b[i] - lastB)
	lastB = b[i]
print(steps)


N = int(input())
p = [0] + list(map(int, input().split()))
count = 0
for i in range(len(p) - 1):
	count += abs(p[i + 1] - p[i])
print(count)


n = int(input())
l = list(map(int, str(input()).strip().split()))
len_l = len(l)
count = abs(l[0])
for i in range(len_l - 1):
	count += abs(l[i] - l[i + 1])
print(count)


n = int(input())
need = 0
cnt = 0
a = []
a = [int(i) for i in input().split()]
for i in range(0, n):
	if a[i] > need:
		cnt += a[i] - need
		need += a[i] - need
	elif a[i] < need:
		cnt += need - a[i]
		need -= need - a[i]
print(cnt)


n = int(input())
B = [int(x) for x in input().split(' ')]
l = 0
t = 0
for b in B:
	t += abs(l - b)
	l = b
print(t)


n = int(input())
s = [int(i) for i in input().split()]
cnt = abs(s[0])
maxi = s[0]
for i in range(1, n):
	if s[i] != maxi:
		cnt += abs(maxi - s[i])
		maxi = s[i]
print(cnt)


n = int(input())
l = list(map(int, input().split()))
s = abs(l[0])
for i in range(1, n):
	s += abs(l[i] - l[i - 1])
print(s)


n = int(input())
b = [int(x) for x in input().split()]
steps = 0
last = None
for number in b:
	additional_steps = abs(number) if last is None else abs(last - number)
	steps += additional_steps
	last = number
print(steps)


from sys import stdin
n = int(stdin.readline())
b = list(map(int, stdin.readline().split()))
cnt = 0
back = 0
for i in range(len(b)):
	if b[i] >= back:
		cnt += b[i] - back
	elif b[i] < back:
		cnt += back - b[i]
	back = b[i]
print(cnt)


def solve():
	N = int(input())
	B = list(map(int, input().split()))
	h = 0
	ans = 0
	for b in B:
		ans += abs(h - b)
		h = b
	print(ans)

def __starting_point():
	solve()
__starting_point()


n = int(input())
b = [int(x) for x in input().split()]
cnt = 0
for i in range(1, n):
	cnt += abs(b[i] - b[i - 1])
print(cnt + abs(b[0]))


n = int(input())
(ans, now) = (0, 0)
for i in map(int, input().split()):
	ans += abs(i - now)
	now = i
print(ans)


n = int(input())
vals = list(map(int, input().split()))
vals = [0] + vals
c = 0
for i in range(n):
	c += abs(vals[i] - vals[i + 1])
print(c)


n = int(input())
a = [0] + list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
	ans += abs(a[i] - a[i - 1])
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.insert(0, 0)
c = 0
for i in range(1, n + 1):
	t = l[i] - l[i - 1]
	c = c + abs(t)
print(c)


n = int(input())
a = list(map(int, input().split()))
pinc = 0
count = 0
for i in range(n):
	a[i] += pinc
	if a[i] > 0:
		pinc -= a[i]
		count += a[i]
		a[i] -= a[i]
	elif a[i] < 0:
		pinc -= a[i]
		count -= a[i]
		a[i] -= a[i]
	else:
		pass
print(count)


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
arr = iia()
prev = ans = 0
for i in arr:
	ans += abs(prev - i)
	prev = i
print(ans)


n = int(input())
value = 0
ans = 0
b = list(map(int, input().split()))
i = 0
while i < n:
	if value == b[i]:
		i += 1
	else:
		ans += abs(value - b[i])
		value = b[i]
		i += 1
print(ans)


def solve(arr, n):
	return sum((abs(arr[i] - arr[i + 1]) for i in range(n - 1))) + abs(arr[0])
n = int(input())
arr = list(map(int, input().split()))
print(solve(arr, n))


n = int(input())
b = list(map(int, input().split()))
a = [0] * n
count = abs(b[0])
for i in range(1, n):
	count += abs(b[i] - b[i - 1])
print(count)


n = int(input())
numbers = [int(a) for a in input().split(' ')]
answer = 0
prev = 0
for i in range(n):
	if numbers[i] != prev:
		answer += abs(numbers[i] - prev)
	prev = numbers[i]
print(answer)


n = int(input())
b = list(map(int, input().split()))
m = 0
s = 0
for i in range(n):
	s += abs(b[i] - m)
	m = b[i]
print(s)


import time
n = int(input())
b = [int(i) for i in input().split()]
start = time.time()
ans = b[0]
if ans < 0:
	ans = -ans
for i in range(1, n):
	d = b[i] - b[i - 1]
	if d < 0:
		d = -d
	ans += d
print(ans)
finish = time.time()


n = int(input())
v = [0]
v1 = [int(i) for i in input().split()]
for i in range(n):
	v.append(v1[i])
r = 0
j = 0
for i in range(n):
	if v[i] > v[i + 1]:
		r += v[i] - v[j]
		r += v[i] - v[i + 1]
		j = i + 1
r += v[n] - v[j]
print(r)


n = input()
if n == '0':
	print(0)
	quit()
data = input()
data = data.split(' ')
for i in range(len(data)):
	data[i] = int(data[i])
ans = abs(data[0])
for i in range(len(data) - 1):
	n = i + 1
	ans += abs(data[n] - data[n - 1])
print(ans)


read = lambda : map(int, input().split())
n = int(input())
a = [0] + list(read())
ans = sum((abs(a[i] - a[i - 1]) for i in range(1, n + 1)))
print(ans)


n = int(input())
mas = []
if n > 1:
	mas = input().split(' ')
	for i in range(len(mas)):
		mas[i] = int(mas[i])
	ish = []
	for i in range(len(mas)):
		ish.append(0)
	s = 0
	r = 0
	for i in range(len(ish)):
		if i > 0:
			s += abs(mas[i] - mas[i - 1])
		else:
			s += abs(mas[i])
	print(s)
else:
	print(0)


n = int(input())
val = list(map(int, input().split(' ')))
r = 0
res = 0
for i in range(n):
	res += abs(val[i] - r)
	r = val[i]
print(res)


def Abs(x):
	if x < 0:
		return -x
	else:
		return x
n = int(input())
a = list(map(int, input().split()))
ans = Abs(a[0])
i = 1
while i < n:
	ans += Abs(a[i] - a[i - 1])
	i += 1
print(ans)


n = int(input())
z = list(input().split())
q = int(z[0])
for i in range(1, n):
	q = abs(q) + abs(int(z[i]) - int(z[i - 1]))
print(q)


tam = int(input())
vetor = list(map(int, input().split()))
x = 0
qtd = 0
tot_soma = 0
while x < tam:
	soma = 0
	vetor[x] += tot_soma
	atual = vetor[x]
	if atual != 0:
		soma += abs(atual)
		qtd += soma
		if atual < 0:
			type_sum = 1
		else:
			type_sum = -1
		soma = type_sum * soma
	tot_soma += soma
	x += 1
print(qtd)


try:
	while True:
		n = int(input())
		b = list(map(int, input().split()))
		cur = 0
		result = 0
		for x in b:
			result += abs(cur - x)
			cur = x
		print(result)
except EOFError:
	pass


n = int(input())
cur = 0
total = 0
list = list(map(int, input().split()))
for item in list:
	total += abs(item - cur)
	cur = item
print(total)


n = int(input())
a = [0] * (n + 1)
b = list(map(int, input().split()))
counter = 0
for i in range(n):
	d = a[i] - b[i]
	counter += abs(d)
	a[i + 1] += b[i]
print(counter)


n = int(input())
l = input().split()
(m, s) = (0, 0)

def dif(a, b):
	if a > b:
		return a - b
	return b - a
for i in range(n):
	x = int(l[i])
	s += dif(x, m)
	if x > m:
		m += dif(x, m)
	elif x < m:
		m -= dif(x, m)
print(s)


n = int(input())
goal = [0] + list(map(int, input().split()))
print(sum((abs(goal[x] - goal[x + 1]) for x in range(n))))


from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from sys import *

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
n = int(z())
arr = zzz()
ans = abs(arr[0])
for i in range(1, n):
	ans += abs(arr[i] - arr[i - 1])
print(ans)


n = int(input())
L = list(map(int, input().split()))
ans = abs(L[0])
for i in range(0, len(L) - 1):
	ans += abs(L[i + 1] - L[i])
print(ans)


import sys
n = int(input())
a = [int(tmp) for tmp in input().split()]
ans = 0
now = 0
for i in range(n):
	ans += abs(a[i] - now)
	now += a[i] - now
print(ans)


input()
ans = int(0)
curr = int(0)
for x in input().split():
	x = int(x)
	ans += abs(curr - x)
	curr = x
print(ans)


def solve():
	ans = 0
	n = int(input())
	l = list(map(int, input().split()))
	lastIndexValue = 0
	for i in l:
		currentIndexValue = i
		steps = abs(currentIndexValue - lastIndexValue)
		ans += steps
		lastIndexValue = currentIndexValue
	return ans
ans = solve()
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
c = sorted(a)
if c == a:
	print(c[n - 1])
else:
	count = 0
	for i in range(n):
		if i == 0:
			count += abs(a[0])
		else:
			count += abs(a[i - 1] - a[i])
	print(count)


n = int(input())
output = 0
lst = list(map(int, input().split()))
output += abs(lst[0])
for i in range(1, n):
	output += abs(lst[i] - lst[i - 1])
print(output)


n = int(input())
b = input().split()
counter = 0
x = 0
for i in b:
	counter += abs(x - int(i))
	x = int(i)
print(counter)


n = int(input())
a = [int(x) for x in input().split()]
answer = abs(a[0])
for i in range(1, n):
	answer += abs(a[i - 1] - a[i])
print(answer)


n = int(input())
p = list(map(int, input().split()))
po = 0
c = 0
for x in range(n):
	if p[x] > po:
		c += p[x] - po
		po += p[x] - po
		c += p[x] - po
	elif p[x] < po:
		c += po - p[x]
		po -= po - p[x]
	else:
		pass
print(c)


n = int(input())
l = list(map(int, input().split()))
t = 0
for i in range(n):
	if i == 0:
		t = t + abs(l[i])
	else:
		t = t + abs(l[i] - l[i - 1])
print(t)


l = int(input())
seq = list(map(lambda x: int(x), input().split(' ')))
val1 = 0
for i in range(0, l - 1):
	val1 = val1 + abs(seq[i] - seq[i + 1])
val1 = val1 + abs(seq[0])
print(val1)


import sys
n = int(input())
a = list(map(int, input().split()))
cur = 0
ans = 0
for i in range(n):
	ans += abs(cur - a[i])
	cur = a[i]
print(ans)


def main():
	input()
	res = a = 0
	for b in map(int, input().split()):
		res += abs(a - b)
		a = b
	print(res)
main()


n = int(input())
line = str('0 ' + input()).split()
line = [int(it) for it in line]
pos = n
num = 0
while pos > 0:
	num += abs(line[pos] - line[pos - 1])
	pos -= 1
print(num)


import unittest
import sys

class Array:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n] = map(int, uinput().split())
		self.nums = list(map(int, uinput().split()))

	def calculate(self):
		result = 0
		delta = 0
		for i in range(self.n):
			result += abs(self.nums[i] - delta)
			delta = self.nums[i]
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '5\n1 2 3 4 5'
		d = Array(test)
		self.assertEqual(d.n, 5)
		self.assertEqual(d.nums, [1, 2, 3, 4, 5])
		self.assertEqual(Array(test).calculate(), '5')
		test = '4\n1 2 2 1'
		self.assertEqual(Array(test).calculate(), '3')
		test = '3\n5 1 2'
		self.assertEqual(Array(test).calculate(), '10')
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Array(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Array().calculate())


n = int(input())
b = list(map(int, input().split()))
add = 0
res = 0
for i in range(n):
	b[i] -= add
	res += abs(b[i])
	add += b[i]
print(res)


n = int(input())
l = list(map(int, input().split()))
a = 0
res = 0
for i in range(n):
	if l[i] > a:
		res += l[i] - a
	elif a > l[i]:
		res += a - l[i]
	a = l[i]
print(res)


n = int(input())
lista = list(map(int, input().split()))
initital = 0
soma = 0
for i in lista:
	if initital != i:
		soma += abs(i - initital)
		initital = i
print(soma)


(n, lst) = (int(input()), [int(i) for i in input().split()])
(pivit, cnt) = (0, 0)
for ele in lst:
	if ele > pivit:
		cnt += ele - pivit
	else:
		cnt += pivit - ele
	pivit = ele
print(cnt)


def main():
	input()
	it = iter(map(int, input().split()))
	res = a = b = 0
	try:
		while True:
			while a == b:
				b = next(it)
			res += abs(a - b)
			a = b
	except StopIteration:
		print(res)
main()


n = int(input())
l = [int(i) for i in input().split()]
intl = 0
res = 0
for i in l:
	res += abs(i - intl)
	intl = i
print(res)


r = c = 0
for x in map(int, [*open(0)][1].split()):
	r += abs(x - c)
	c = x
print(r)


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(xs, n):
	return abs(xs[0]) + sum((abs(b - a) for (a, b) in zip(xs, xs[1:])))

def main():
	n = int(input())
	xs = [int(_c) for _c in input().strip().split()]
	assert len(xs) == n
	result = solve(xs, n)
	print(result)
main()


N = int(input())
A = list(map(int, input().split()))
ans = 0
now = 0
for a in A:
	ans += abs(now - a)
	now = a
print(ans)


n = int(input())
s = input()
b = [int(i) for i in s.split(' ')]
k = 0
a = 0
for i in b:
	k += abs(i - a)
	a = i
print(k)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, arr):
	if n == 1:
		print(*arr)
	else:
		c = 0
		tmp = 0
		for i in range(n):
			c += abs(arr[i] - tmp)
			tmp = arr[i]
		print(c)
n = int(input())
a = int_arr()
solve(n, a)


n = int(input())
b = list(map(int, input().split()))
moves = 0
t = 0
for i in range(n):
	diff = abs(b[i] - t)
	t += b[i] - t
	moves += diff
print(moves)


N = int(input())
M = list(map(int, input().split()))
A = abs(M[0])
B = M[0]
for i in range(1, N):
	A += abs(M[i] - B)
	B += M[i] - B
print(A)


n = int(input())
ar = list(map(int, input().split()))
total = 0
total = abs(ar[0])
for i in range(1, len(ar)):
	delta = ar[i] - ar[i - 1]
	total += abs(delta)
print(total)


n = int(input())
m = list(map(int, input().split()))[:n]
s = abs(m[0])
for i in range(1, n):
	d = abs(m[i] - m[i - 1])
	s = s + d
print(s)


import sys
import math
import bisect

def solve(A):
	n = len(A)
	ans = 0
	for i in range(n):
		if i == 0:
			ans += abs(A[0])
		else:
			ans += abs(A[i] - A[i - 1])
	return ans

def main():
	n = int(input())
	A = list(map(int, input().split()))
	ans = solve(A)
	print(ans)
main()


n = int(input())
entrada = input()
entrada_int = list(map(int, entrada.split(' ')))
vetor = entrada_int
soma = 0
aux = 0
for i in vetor:
	soma += max(aux - i, i - aux)
	aux = i
print(soma)


n = int(input())
array = [int(c) for c in input().split()]
steps = abs(array[0])
for i in range(1, n):
	steps += abs(array[i] - array[i - 1])
print(steps)


n = int(input())
b = list(map(int, input().split()))
prev = 0
ans = 0
for v in b:
	ans += abs(v - prev)
	prev = v
print(ans)


n = int(input())
ms = 0
x = list(map(int, input().split()))
for i in range(n):
	if i > 0:
		ms += abs(x[i] - x[i - 1])
	else:
		ms += abs(x[i])
print(ms)


n = int(input().strip())
b = [0] + list(map(int, input().strip().split()))
total = 0
for i in range(1, len(b)):
	total += abs(b[i] - b[i - 1])
print(total)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
c = abs(lst[0])
for j in range(1, n):
	c += abs(lst[j] - lst[j - 1])
print(c)


n = int(input())
a = list(map(int, input().split()))
c = 0
p = 0
for i in range(n):
	if p != a[i]:
		c = c + abs(a[i] - p)
		p = a[i]
print(c)


n = int(input())
data = [int(i) for i in input().split()]
steps = 0
diff = 0
for i in data:
	if diff != i:
		steps += abs(i - diff)
		diff += i - diff
print(steps)


num = int(input())
l = list(map(int, input().rstrip().split()))
sum = abs(l[0])
past = l[0]
for i in range(1, num):
	if past == l[i]:
		continue
	elif past > l[i]:
		sum = sum + (past - l[i])
		past = l[i]
	else:
		sum = sum + (l[i] - past)
		past = l[i]
print(sum)


n = int(input())
r = [int(k) for k in input().split()]
q = abs(r[0])
for j in range(1, n):
	q += abs(r[j] - r[j - 1])
print(q)


n = int(input())
arr = list(map(int, input().split()))
s = sum((abs(arr[i] - arr[i - 1]) for i in range(1, n)))
print(s + abs(arr[0]))


def mp():
	return map(int, input().split())

def lt():
	return list(map(int, input().split()))

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)
n = it()
a = lt()
result = abs(a[0])
for i in range(len(a) - 1):
	result += abs(a[i] - a[i + 1])
print(result)


n = int(input())
f = list(map(int, input().split()))
c = abs(f[0])
for i in range(len(f) - 1):
	c = c + abs(f[i + 1] - f[i])
print(c)


import sys
n = int(input())
a = list(map(int, input().split()))
cnt = pre = 0
for i in range(n):
	if a[i] != pre:
		cnt += abs(a[i] - pre)
	pre = a[i]
print(cnt)


n = input()
a = list(map(int, input().split()))
ans = 0
k = 0
for i in a:
	ans += abs(i - k)
	k += i - k
print(ans)


def arr_inp():
	return [int(x) for x in input().split()]
(n, a) = (int(input()), arr_inp())
s = abs(a[0])
for i in range(1, n):
	s += abs(a[i] - a[i - 1])
print(s)


n = int(input())
a = list(map(int, input().split()))
(ans, offset) = (0, 0)
for v in a:
	ans += abs(v - offset)
	offset = v
print(ans)


import sys
n = int(input())
l = [int(x) for x in input().split()]
(a, b) = (0, 0)
for i in l:
	a += abs(i - b)
	b = i
print(a)


n = int(input())
val = [0] + [int(x) for x in input().split()]
res = 0
for i in range(1, n + 1):
	res += abs(val[i] - val[i - 1])
print(res)


n = int(input())
array_a = list()
aux = input().split(' ')
for a in aux:
	array_a.append(int(a))
add = 0
sub = 0
steps = 0
current = 0
for i in range(n):
	current = add - sub
	if current == array_a[i]:
		continue
	elif current < array_a[i]:
		add += array_a[i] - current
		steps += array_a[i] - current
	else:
		sub += current - array_a[i]
		steps += current - array_a[i]
print(steps)


n = int(input())
b = list(map(int, input().split()))
moves = 0
sum = 0
for i in range(n):
	moves += abs(b[i] + sum)
	sum -= b[i] + sum
print(moves)


n = int(input())
l = list(map(int, input().split()))
av = 0
ans = 0
for i in range(n):
	ans += abs(av - l[i])
	av = l[i]
print(ans)


n = int(input())
b = list(map(int, input().split()))
cur = 0
ans = 0
for i in range(len(b)):
	ans += abs(cur - b[i])
	cur = b[i]
print(ans)


n = int(input())
b = list(map(int, input().rstrip().split()))
state = 0
count = 0
for x in b:
	if state < x:
		count += x - state
	elif state > x:
		count += state - x
	state = x
print(count)


n = int(input())
l = list(map(int, input().split()))
z = abs(l[0])
for i in range(1, len(l)):
	z = z + abs(l[i - 1] - l[i])
print(z)


import os
import sys
from math import *
from collections import *
from itertools import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase
from typing import overload

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(1):
	n = Int()
	a = array()
	(cur, ans) = (0, 0)
	for i in a:
		need = i - cur
		ans += abs(need)
		cur = i
	print(ans)


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
arr = int_arr()
prev = 0
ct = 0
for i in range(n):
	ct += abs(arr[i] - prev)
	prev = arr[i]
print(ct)


n = int(input())
a = [int(x) for x in input().split()]
cur = 0
ans = 0
for x in a:
	ans += abs(cur - x)
	cur = x
print(ans)


t = int(input())
nums = list(map(int, list(input().split())))
ans = abs(nums[0])
for r in range(0, t - 1):
	ans += abs(nums[r] - nums[r + 1])
print(ans)


n = int(input())
L = [int(x) for x in input().split()]
print(sum((abs(L[i + 1] - L[i]) for i in range(len(L) - 1))) + abs(L[0]))


n = int(input())
a = map(int, input().split())
(s, p) = (0, 0)
for i in a:
	s = s + abs(i - p)
	p = i
print(s)


n = int(input())
a = [int(s) for s in input().split()]
sum = abs(a[0])
for i in range(n - 1):
	sum += abs(a[i + 1] - a[i])
print(sum)


n = int(input())
arr = list(map(int, input().split()))
c = 0
count = 0
for i in range(n):
	res = arr[i] - count
	count += res
	if res == 0:
		continue
	c += abs(res)
print(c)


n = int(input())
lt = [int(x) for x in input().split()]
ans = 0
for i in range(1, n):
	ans += abs(lt[i] - lt[i - 1])
print(ans + abs(lt[0]))


n = int(input())
l = list(map(int, input().split()))
s = p = 0
for i in l:
	s += abs(i - p)
	p = i
print(s)


n = int(input())
s = [0] * n
lst = list(map(int, input().split()))
summa = 0
cnt = 0
for i in range(n):
	cnt += abs(lst[i] - summa)
	summa = lst[i]
print(cnt)


n = int(input())
a = list(input().split(' '))
ans = 0
for i in range(0, n):
	if i == 0:
		ans = ans + abs(int(a[0]))
	else:
		ans = ans + abs(int(a[i]) - int(a[i - 1]))
print(ans)


s = 0
cur = 0
x = int(input())
y = list(map(int, input().split(' ')))
for i in y:
	off = i + cur
	add = -off
	s += abs(add)
	cur += add
print(s)


n = int(input())
b = input().split(' ')
b = map(int, b)
b = list(b)
a = [0] * n
i = 0
acc = 0
count = 0
while i < n:
	a[i] += acc
	delta = b[i] - a[i]
	acc += delta
	count += abs(delta)
	i += 1
print(count)


a = int(input())
x = list(map(int, input().split()))
t = abs(x[0])
if a > 1:
	for i in range(1, a):
		t += abs(x[i - 1] - x[i])
print(t)


def array(bs):
	s = 0
	k = 0
	for b in bs:
		s += abs(b - k)
		k = b
	return s
n = int(input())
bs = tuple(map(int, input().split()))
print(array(bs))


n = int(input())
b = list(map(int, input().split()))
cur = 0
cnt = 0
for i in range(n):
	cnt += abs(cur - b[i])
	cur = b[i]
print(cnt)


N = int(input())
arr = list(map(int, input().split()))
ans = abs(arr[0])
for i in range(1, N):
	ans += abs(arr[i] - arr[i - 1])
print(ans)


n = input()
c = mx = 0
for i in input().split():
	if i != mx:
		c += abs(mx - int(i))
		mx = int(i)
print(c)


import sys
n = int(input())
b = list(map(int, sys.stdin.readline().split()))
ans = abs(b[0])
for i in range(len(b) - 1):
	ans += abs(b[i + 1] - b[i])
print(ans)


class CodeforcesTask596BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.array = []

	def read_input(self):
		self.n = int(input())
		self.array = [int(x) for x in input().split(' ')]

	def process_task(self):
		steps = 0
		for x in range(self.n):
			steps += abs(self.array[x] - (0 if not x else self.array[x - 1]))
		self.result = str(steps)

	def get_result(self):
		return self.result
Solution = CodeforcesTask596BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
a = [0] * n
b = list(map(int, input().split()))
s = 0
for x in range(1, n):
	s += abs(b[x - 1] - b[x])
print(s + abs(b[0]))


n = int(input())
b = list(map(int, input().split()))
t = 0
ans = 0
for bx in b:
	ans += abs(t - bx)
	t = bx
print(ans)


N = int(input())
B = [int(b) for b in input().split()]
level = 0
step = 0
for i in range(N):
	if not B[i] == level:
		step += abs(B[i] - level)
		level = B[i]
print(step)


n = int(input())
A = list(map(int, input().split()))
x = abs(A[0])
for i in range(1, n):
	x += abs(A[i] - A[i - 1])
print(x)


n = int(input())
a = list(map(int, input().split()))
(z, f) = (0, 0)
for i in range(n):
	if i == 0:
		if a[0] >= 0:
			z += a[0]
		else:
			f -= a[0]
	elif a[i] - a[i - 1] >= 0:
		z += a[i] - a[i - 1]
	else:
		f -= a[i] - a[i - 1]
print(z + f)


n = int(input())
bn = [int(i) for i in input().split()]
count = abs(bn[0])
for b in range(len(bn) - 1):
	count += abs(bn[b + 1] - bn[b])
print(count)


def main():
	n = int(input())
	A = [0 for _ in range(n)]
	B = list(map(int, input().split()))
	other = 0
	k = 0
	for i in range(n):
		b = B[i]
		d = b - other
		k += abs(d)
		other += d
	return k
print(main())


n = int(input().split()[0])
line = input().split()
result = 0
k = 0
for element in line:
	result += abs(k - int(element))
	k = int(element)
print(result)


a = 0
b = 0
p = 0
curr = 0
n = int(input())
values = input()
values = values.split()
for i in range(n):
	curr = a - b
	if curr != int(values[i]) and curr >= int(values[i]):
		b += curr - int(values[i])
		p += curr - int(values[i])
	elif curr != int(values[i]) and curr < int(values[i]):
		a += int(values[i]) - curr
		p += int(values[i]) - curr
print(p)


import sys
from sys import stdin, stdout
import math
from math import sqrt
n = int(input())
array = [int(x) for x in stdin.readline().rstrip().split()]
cur_value = 0
nb_steps = 0
for i in range(len(array)):
	v_array = array[i]
	if not v_array == cur_value:
		nb_steps += abs(cur_value - v_array)
		cur_value = v_array
print(nb_steps)


mx = 200005
bit = [0 for i in range(mx)]

def read(i):
	s = 0
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def upd(i, v):
	while i < mx:
		bit[i] += v
		i += i & -i
n = int(input())
a = [0 for i in range(n)]
b = [int(x) for x in input().split()]
cnt = 0
for i in range(n):
	x = read(i + 1)
	if x == b[i]:
		continue
	diff = b[i] - x
	upd(i + 1, diff)
	if diff < 0:
		diff = -diff
	cnt += diff
print(cnt)


t = int(input())
arr = list(map(int, input().strip().split()))[:t]
ans = 0
for i in range(1, t):
	ans = ans + abs(arr[i] - arr[i - 1])
x = abs(arr[0])
y = ans + x
print(y)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	a = LI()
	r = abs(a[0])
	for i in range(1, n):
		r += abs(a[i] - a[i - 1])
	return r
print(main())


n = int(input())
array = list(map(int, input().split()))
lastElem = 0
actions = 0
for i in array:
	actions += abs(i - lastElem)
	lastElem = i
print(actions)


n = int(input())
l = list(map(int, input().split()))
count = abs(l[0])
for i in range(n - 1):
	c = abs(l[i] - l[i + 1])
	count += c
print(count)


import sys
input_file = sys.stdin
input_file.readline()
moves = 0
array = [0] + list(map(int, input_file.readline().rstrip().split()))
for i in range(1, len(array)):
	moves += abs(array[i] - array[i - 1])
print(moves)


n = int(input())
l = list(map(int, input().split()))
cc = 0
c = l[0]
count = abs(l[0])
i = 1
while i < n:
	if l[i] < l[i - 1]:
		k = i
		kk = 0
		while k < n:
			if l[k] > l[k - 1]:
				count += c - l[k - 1]
				c = l[k - 1]
				i = k - 1
				break
			elif k == n - 1:
				count += c - l[k]
				i = k
				break
			k += 1
	elif l[i] > l[i - 1]:
		k = i
		kk = 0
		while k < n:
			if l[k] < l[k - 1]:
				count += abs(l[k - 1] - c)
				c = l[k - 1]
				i = k - 1
				break
			elif k == n - 1:
				count += l[k] - c
				i = k
				break
			k += 1
	i += 1
print(count)


n = int(input())
a = [int(i) for i in input().split()]
a.append(0)
m = 0
for i in range(n):
	m += abs(a[i] - a[i - 1])
print(m)


n = int(input())
s = [0] + [int(i) for i in input().split()]
ans = 0
for i in range(1, n + 1):
	if s[i] > s[i - 1]:
		ans += s[i] - s[i - 1]
	if s[i] < s[i - 1]:
		ans += s[i - 1] - s[i]
print(ans)


n = int(input())
b = list(map(int, input().split()))
b.append(0)
ans = 0
for i in range(n):
	ans += abs(b[i] - b[i - 1])
print(ans)


n = int(input())
b = [int(x) for x in input().split()]
res = 0
cur_val = 0
for num in range(0, n):
	res += abs(b[num] - cur_val)
	cur_val += b[num] - cur_val
print(res)


input()
A = [0] + list(map(int, input().split()))
print(sum((abs(a - b) for (a, b) in zip(A, A[1:]))))


n = int(input())
arr = list(map(int, input().split()))
cur = 0
tot = 0
for i in range(n):
	numOp = abs(cur - arr[i])
	cur = arr[i]
	tot += numOp
print(tot)


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
acum = 0
ans = 0
for i in range(n):
	x = s[i] - acum
	if x != 0:
		ans += abs(x)
		acum = s[i]
print(ans)


n = int(input())
x = list(map(int, input().split()))
c = 0
t = 0
for i in x:
	c += abs(t - i)
	t = i
print(c)


n = int(input())
a = [0] + list(map(int, input().split()))
moves = 0
for i in range(1, len(a)):
	if a[i] > a[i - 1]:
		moves += a[i] - a[i - 1]
	else:
		moves += a[i - 1] - a[i]
print(moves)


def solve(n, arr):
	ways = 0
	index = 0
	curr = 0
	while index < n:
		if arr[index] > curr:
			ways += arr[index] - curr
		elif arr[index] < curr:
			ways += curr - arr[index]
		curr = arr[index]
		index += 1
	return ways
print(solve(int(input()), list(map(int, input().split()))))


n = input()
b = map(int, input().split(' '))
ans = 0
cnt = 0
for i in b:
	sub = i - cnt
	ans += abs(sub)
	cnt += sub
print(ans)


n = int(input())
b = list(map(int, input().split()))
r = abs(b[0])
for i in range(1, n):
	r += abs(b[i] - b[i - 1])
print(r)


from sys import stdin
from collections import defaultdict
from operator import itemgetter

def main():
	n = int(stdin.readline())
	xs = map(int, stdin.readline().split())
	print('{}'.format(run(n, xs)))

def run(n, xs):
	prev = 0
	moves = 0
	for x in xs:
		if x != prev:
			moves += abs(x - prev)
		prev = x
	return moves
main()


n = int(input())
a = list(map(int, input().split()))
prev = 0
S = 0
for i in range(n):
	S += abs(a[i] - prev)
	prev = a[i]
print(S)


n = int(input())
c = 0
mas = [int(x) for x in input().split()]
for i in range(n - 1):
	c += abs(mas[i] - mas[i + 1])
print(c + abs(mas[0]))


n = int(input())
arr = list(map(int, input().split()))
(prev, res) = (0, 0)
for i in arr:
	res += abs(prev - i)
	prev = i
print(res)


n = int(input())
arr = list(map(int, input().split()))
c = 0
for i in range(0, n):
	if i > 0:
		c += abs(arr[i] - arr[i - 1])
	else:
		c += abs(arr[i])
print(c)


def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	x = 0
	ans = 0
	for i in range(n):
		if a[i] - x != 0:
			prev_x = x
			x += a[i] - x
			ans += abs(x - prev_x)
	return ans
print(main())


def vilbur(lst):
	a = [0] + lst
	count = 0
	for i in range(len(a) - 1):
		count += abs(a[i + 1] - a[i])
	return count
n = int(input())
b = [int(j) for j in input().split()]
print(vilbur(b))


n = int(input())
array_b = input().split()
array_b = [int(x) for x in array_b]
current_value = 0
count = 0
for idx in range(n):
	while current_value != array_b[idx]:
		if current_value < array_b[idx]:
			differ = array_b[idx] - current_value
			current_value += differ
			count += differ
		else:
			differ = current_value - array_b[idx]
			current_value -= differ
			count += differ
print(count)


n = int(input())
arr = [int(x) for x in input().split()]
resp = 0
a = 0
for i in range(n):
	resp += abs(arr[i] - a)
	a = arr[i]
print(resp)


n = int(input())
B = list(map(int, input().split()))
k = 0
A = [0] * n
i = 0
k += abs(B[0] - A[0])
for i in range(n - 1):
	k += abs(B[i + 1] - B[i])
print(k)


n = int(input())
v = [int(x) for x in input().split(' ')]
sm = abs(v[0])
for c in range(n - 1):
	sm += abs(v[c + 1] - v[c])
print(sm)


n = int(input())
a = list(map(int, input().split()))
cnt = a[0]
a = [abs(a[i] - a[i - min(i, 1)]) for i in range(1, n)]
print(sum(a) + abs(cnt))


I = lambda : list(map(int, input().split()))
n = int(input())
b = I()
print(abs(b[0]) + sum([abs(b[i] - b[i - 1]) for i in range(1, n)]))


q = int(input())
arr = list(map(int, input().split(' ')))
s = abs(arr[0])
for i in range(1, q):
	s = s + abs(arr[i] - arr[i - 1])
print(s)


import math

class Input:

	def readInt(self):
		return int(input())

	def readIntArray(self):
		return [int(x) for x in input().split(' ')]

	def readString(self):
		return input()

	def readStringArray(self):
		return input().split(' ')

	def readFloat(self):
		return float(input())

	def readFloatArray(self):
		return [float(x) for x in input().split(' ')]

def main():
	inp = Input()
	n = inp.readInt()
	b = inp.readIntArray()
	start = 0
	operations = 0
	for i in range(n):
		operations += abs(b[i] - start)
		start = b[i]
	print(operations)
main()


n = int(input())
b = [0]
b.extend([int(i) for i in input().split()])
count = 0
for i in range(1, n + 1, 1):
	num_op = b[i - 1] - b[i]
	count += max(num_op, -num_op)
print(count)


n = int(input())
a = 0
b = list(map(int, input().split()))
h = 0
for i in range(n):
	h += abs(a - b[i])
	a = b[i]
print(h)


a = int(input())
t = list(map(int, input().split()))
p = 0
for k in range(a):
	if k == 0:
		p += abs(t[k])
	elif t[k] != t[k - 1]:
		p += abs(t[k] - t[k - 1])
print(p)


n = int(input())
b = [int(s) for s in input().split()]
ops = 0
val = 0
i = 0
while i < n:
	delta = b[i] - val
	ops += abs(delta)
	val = b[i]
	i += 1
print(ops)


n = int(input())
b = [int(x) for x in input().split()]
t = int(0)
for i in range(n):
	if i == 0:
		t += abs(b[0])
	else:
		t += abs(b[i] - b[i - 1])
print(t)


n = int(input())
x = list(map(int, input().split()))
ans = 0
val = 0
for i in range(n):
	ans += abs(x[i] - val)
	val += x[i] - val
print(ans)


N = int(input())
nl = 0
Ans = 0
In = input().split(' ')
for wi in range(0, N):
	Ans += abs(nl - int(In[wi]))
	nl = int(In[wi])
print(Ans)


__author__ = 'artyom'

def main():
	read(0)
	p = s = 0
	for v in read(3):
		s += abs(v - p)
		p = v
	return s

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
write(main())


n = int(input())
seq = input().split()
seq = [0] + [int(x) for x in seq]
total = 0
for i in range(len(seq) - 1):
	total += abs(seq[i] - seq[i + 1])
print(total)


a = int(input())
b = input().split()
(c, s) = (0, 0)
for i in b:
	s += abs(int(i) - c)
	c = int(i)
print(s)


n = int(input())
bs = list(map(int, input().split()))

def solve(n, bs):
	steps = 0
	level = 0
	for b in bs:
		steps += abs(level - b)
		level = b
	return steps
print(solve(n, bs))


(N, X) = (int(input()), list(map(int, input().split())))
(Sum, Value) = (0, 0)
for i in range(N):
	Sum += abs(X[i] - Value)
	Value = X[i]
print(Sum)


n = int(input())
x = list(map(int, input().split()))
total = 0
heritage = 0
for i in range(len(x)):
	change = x[i] - heritage
	heritage += change
	total += abs(change)
print(total)


n = int(input())
a = list(map(int, input().split()))
s = 0
steps = 0
for e in a:
	steps += abs(e - s)
	s = e
print(steps)


l = [0]
n = int(input())
l.extend(list(map(int, input().split())))
c = 0
f = 0
i = 1
while i <= n:
	f += abs(l[i] - l[i - 1])
	i += 1
print(f)


n = int(input())
b = [int(i) for i in input().split()]
last = 0
res = 0
for i in b:
	res += abs(i - last)
	last = i
print(res)


n = int(input())
s = list(map(int, input().split()))
ans = 0
l = [0] * n
amp = 0
pref = 0
for i in range(n):
	l[i] += pref
	amp = abs(l[i] - s[i])
	if l[i] <= s[i]:
		l[i] += amp
		pref += amp
	else:
		l[i] -= amp
		pref -= amp
	ans += amp
print(ans)


def main():
	n = int(input())
	b = [int(i) for i in input().split(' ')]
	cur = 0
	res = 0
	for v in b:
		res += abs(v - cur)
		cur += v - cur
	print(res)
main()


n = int(input())
arr_b = [int(b) for b in input().split()]
arr_b = [0] + arr_b
result = 0
i = 1
while i <= n:
	result += abs(arr_b[i] - arr_b[i - 1])
	i += 1
print(result)


n = int(input())
arr = input()
target = [int(x) for x in arr.split()]
op = 0
diff = 0
operation = 0
for i in range(n):
	diff = target[i] - operation
	operation += diff
	if not diff == 0:
		op += abs(diff)
print(op)