As the title suggests, this is the hard-core version of  another neat kata.

The task is simple to explain: simply sum all the numbers from the first parameter being the beginning to the second parameter being the upper limit (possibly included), going in steps expressed by the third parameter:

```python
sequence_sum(2, 2, 2) # 2
sequence_sum(2, 6, 2) # 12 (= 2 + 4 + 6)
sequence_sum(1, 5, 1) # (= 1 + 2 + 3 + 4 + 5)
sequence_sum(1, 5, 3) # 5 (= 1 + 4)
```

If it is an impossible sequence (with the beginning being larger the end and a positive step or the other way around), just return `0`. See the provided test cases for further examples :)

**Note:** differing from the other base kata, much larger ranges are going to be tested, so you should hope to get your algo optimized and to avoid brute-forcing your way through the solution.

Source: codewars | Difficulty: EASY

Starter code: def sequence_sum(b, e, s):
	

Solutions:
def sequence_sum(a, b, step):
	n = (b - a) // step
	return 0 if n < 0 else (n + 1) * (n * step + a + a) // 2


def sequence_sum(b, e, s):
	(q, r) = divmod(e - b, s)
	return (b + e - r) * max(q + 1, 0) // 2


def sequence_sum(start, stop, step):
	n = (stop - start) // step
	last = start + n * step
	return (n + 1) * (start + last) // 2 if n >= 0 else 0


def sequence_sum(b, e, s):
	if s > 0 and b > e or (s < 0 and b < e):
		return 0
	near = e - (e - b) % s
	n = (near - b) // s + 1
	return (b + near) * n // 2


def sequence_sum(b, e, s):
	if b > e and s > 0 or (b < e and s < 0):
		return 0
	k = (e - b) // s
	return b * (k + 1) + s * (k * (k + 1)) // 2


def sequence_sum(begin, end, step):
	n = int((end - begin + step) / step)
	an = begin + (n - 1) * step
	if step > 0:
		if begin > end:
			return 0
	if step < 0:
		if begin < end:
			return 0
	if n % 2 == 0:
		res = int(int(n / 2) * (begin + an))
	if (begin + an) % 2 == 0:
		res = int(int((begin + an) / 2) * n)
	return res


from decimal import Decimal

def sequence_sum(s, e, step):
	if s > e and step > 0 or (s < e and step < 0):
		return 0
	elems = abs(s - e) // abs(step) + 1
	last = s + step * (elems - 1)
	avg = (s + last) / 2
	return int(Decimal(elems) * Decimal(avg))


def sequence_sum(a, b, s):
	n = (b - a) // s
	return 0 if n < 0 else (n + 1) * (2 * a + s * n) // 2