# Task
 You are given a regular array `arr`. Let's call a `step` the difference between two adjacent elements. 
 
 Your task is to sum the elements which belong to the sequence of consecutive elements of length `at least 3 (but as long as possible)`, such that the steps between the elements in this sequence are the same.

 Note that some elements belong to two sequences and have to be counted twice.

# Example

 For `arr = [54, 70, 86, 1, -2, -5, 0, 5, 78, 145, 212, 15]`, the output should be `639`.
```
There are 4 sequences of equal steps in the given array:
{54, 70, 86} => step +16
{1, -2, -5} => step -3
{-5, 0, 5} => step +5
{78, 145, 212} => step +67
So the answer is 
(54 + 70 + 86) + 
(1 - 2 - 5) + 
(-5 + 0 + 5) + 
(78 + 145 + 212) = 639.
The last element 15 was not be counted.
```

 For `arr = [7, 2, 3, 2, -2, 400, 802]`, the output should be `1200`.
 ```
 There is only 1 sequence in arr:
 {-2, 400, 802} => step +402
 So the answer is: -2 + 400 + 802 = 1200
 ```
 
 For `arr = [1, 2, 3, 4, 5]`, the output should be `15`.
 
 Note that we should only count {1, 2, 3, 4, 5} as a whole, any other small subset such as {1, 2, 3},{2, 3, 4},{3, 4, 5} are belong to {1, 2, 3, 4, 5}.
 
# Input/Output


 - `[input]` array.integer `arr`

 `3 ≤ arr.length ≤ 100`


 - `[output]` an integer
 
 The sum of sequences.

Difficulty: EASY
Starter code: def sum_of_regular_numbers(arr):
	

Solutions:
def sum_of_regular_numbers(arr):
	(res, value, save) = (0, arr[1] - arr[0], arr[:2])
	for (x, y) in zip(arr[1:], arr[2:]):
		if y - x == value:
			save.append(y)
		else:
			if len(save) >= 3:
				res += sum(save)
			(value, save) = (y - x, [x, y])
	if len(save) >= 3:
		res += sum(save)
	return res


from itertools import groupby
from operator import itemgetter

def sum_of_regular_numbers(arr):
	xs = [(i, x - y) for (i, (x, y)) in enumerate(zip(arr, arr[1:]))]
	it = (list(grp) for (key, grp) in groupby(xs, key=itemgetter(1)))
	it = ((grp[0][0], len(grp)) for grp in it if len(grp) > 1)
	return sum((sum(arr[i:i + n + 1]) for (i, n) in it))


def sum_of_regular_numbers(arr):
	grouped = [(b - a, 1, a) for (a, b) in zip(arr[:-1], arr[1:])]
	i = 0
	while i < len(grouped) - 1:
		if grouped[i][0] == grouped[i + 1][0]:
			grouped[i] = (grouped[i][0], grouped[i][1] + 1, grouped[i][2])
			del grouped[i + 1]
		else:
			i += 1
	return sum(((2 * base + step * steps) * ((steps + 1) / 2) for (step, steps, base) in grouped if steps >= 2))


def sum_of_regular_numbers(arr):
	(i, s) = (0, 0)
	while i < len(arr) - 2:
		(n, step) = (1, arr[i] - arr[i + 1])
		while i + 1 + n < len(arr) and arr[i + n] - arr[i + 1 + n] == step:
			n += 1
		if n >= 2:
			s += sum(arr[i:i + n + 1])
		i += n
	return s


def sum_of_regular_numbers(arr):
	i = s = 0
	l = len(arr)
	while i < l - 1:
		(temp, diff) = ([], arr[i + 1] - arr[i])
		while i < l - 1 and arr[i + 1] - arr[i] == diff:
			temp.extend([arr[i], arr[i + 1]])
			i += 1
		if len(set(temp)) > 2:
			s += sum(set(temp))
	return s


def sum_of_regular_numbers(arr):
	sum_ = 0
	i = 0
	while i < len(arr) - 1:
		seq = [arr[i], arr[i + 1]]
		step = arr[i] - arr[i + 1]
		j = i + 1
		while j < len(arr) - 1:
			if arr[j] - arr[j + 1] != step:
				break
			seq.append(arr[j + 1])
			j += 1
		if len(seq) >= 3:
			sum_ += sum(seq)
		i = j
	return sum_


from itertools import groupby

def sum_of_regular_numbers(a):
	(b, i, r) = ([sum((1 for _ in y)) for (x, y) in groupby((y - x for (x, y) in zip(a, a[1:])))], 0, 0)
	for x in b:
		if x > 1:
			r += sum(a[i:i + x + 1])
		i += x
	return r


import numpy as np
from itertools import groupby

def sum_of_regular_numbers(arr):
	lst = [list(g) for (k, g) in groupby(np.diff(arr))]
	(idx, ans) = (0, 0)
	for i in lst:
		if len(i) > 1:
			ans += sum(arr[idx:idx + len(i) + 1])
		idx = idx + len(i)
	return ans


from itertools import groupby

def sum_of_regular_numbers(arr):
	(r, i) = (0, 0)
	for (k, g) in groupby((j - i for (i, j) in zip(arr, arr[1:]))):
		x = len(list(g))
		if x > 1:
			r += sum(arr[i:i + x + 1])
		i += x
	return r


from itertools import groupby

def sum_of_regular_numbers(arr):
	res = [[b - a, i] for (i, a, b) in zip(range(len(arr)), arr, arr[1:])]
	ans = 0
	for (_, g) in groupby(res, key=lambda x: x[0]):
		lst = list(g)
		if len(lst) > 1:
			ans += sum(arr[lst[0][1]:lst[-1][1] + 2])
	return ans