AtCoder Beginner Contest 099 - Stone Monument

In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.
It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.
Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.
Assume also that the depth of the snow cover is always at least 1 meter.

-----Constraints-----
 - 1 \leq a < b < 499500(=1+2+3+...+999)
 - All values in input are integers.
 - There is no input that contradicts the assumption.

-----Input-----
Input is given from Standard Input in the following format:
a b

-----Output-----
If the depth of the snow cover is x meters, print x as an integer.

-----Sample Input-----
8 13

-----Sample Output-----
2

The heights of the two towers are 10 meters and 15 meters, respectively.
Thus, we can see that the depth of the snow cover is 2 meters.

Difficulty: EASY

Starter code:

Solutions:
(a, b) = map(int, input().split())
height = (b - a) * (b - a + 1) // 2
ans = height - b
print(ans)


(a, b) = map(int, input().split())
print(int((b - a) * (b - a + 1) / 2) - b)


(a, b) = list(map(int, input().split()))
print(sum(range(b - a)) - a)


(a, b) = [int(x) for x in input().split()]
print(1 * (b - a + 1) * (b - a) // 2 - b)


(A, B) = map(int, input().split())
c = B - A
print(c * (c + 1) // 2 - B)


(a, b) = map(int, input().split())
N = b - a
B = N * (N + 1) // 2
ans = B - b
print(ans)


(a, b) = map(int, input().split())
n = b - a - 1
x = (n ** 2 + n - a * 2) // 2
print(x)


(a, b) = map(int, input().split())
c = b - a
d = 0
for i in range(1, c):
	d += i
print(d - a)


def mapt(fn, *args):
	return tuple(map(fn, *args))

def Input():
	return mapt(int, input().split(' '))

def main():
	(a, b) = Input()
	towers = [1] * 999
	for i in range(1, 999):
		towers[i] = towers[i - 1] + i + 1
	n = b - a
	ans = 0
	for i in range(998):
		if towers[i + 1] - towers[i] == n:
			ans = towers[i] - a
	print(ans)
main()


(a, b) = map(int, input().split())
d = b - a
m = d * (d - 1) // 2
print(m - a)


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


(x, y) = map(int, input().split())
tmp = y - x
print((tmp + 1) * tmp // 2 - y)


(a, b) = map(int, input().split())
c = b - a
s = (1 + c) * c // 2
print(s - b)


(x, y) = map(int, input().split())
tower = []
for i in range(1, 1000):
	tower.append(i * (i + 1) / 2)
for n in range(0, 998):
	if tower[n] - x == tower[n + 1] - y:
		print(int(tower[n] - x))


(a, b) = map(int, input().split())
print(sum(range(b - a + 1)) - b)


(A, B) = [int(s) for s in input().split()]
x = B - A
y = x * (x - 1) // 2
print(y - A)


(a, b) = map(int, input().split())
ans = 0
for num in range(1, b - a):
	ans += num
print(ans - a)


(a, b) = map(int, input().split())
c = b - a
wa = c * (c + 1) // 2
print(wa - b)


(a, b) = map(int, input().split())
c = b - a
print((c * c + c) // 2 - b)


(a, b) = [int(i) for i in input().split()]
b_no_snow = sum(range(1, b - a + 1))
print(b_no_snow - b)


(a, b) = map(int, input().split())
c = b - a
ans = 0
for i in range(c):
	ans += i
print(ans - a)


(a, b) = map(int, input().split())
k = b - a
al = (1 + k) * k
al //= 2
print(al - b)


(a, b) = list(map(int, input().split()))
n = b - a - 1
an = n * (n + 1) // 2
print(an - a)


(a, b) = map(int, input().split())
h = b - a
x = h * (1 + h) // 2 - b
print(x)


(x, y) = map(int, input().split())
n = y - x
print(n * (n + 1) // 2 - y)


(a, b) = map(int, input().split())
print(sum((i for i in range(b - a))) - a)


(a, b) = map(int, input().split())
n = b - a
real_b = n * (n + 1) // 2
print(real_b - b)


(a, b) = (int(T) for T in input().split())
print((b - a) * (b - a + 1) // 2 - b)


(a, b) = list(map(int, input().split()))
D = b - a
print(D * (D + 1) // 2 - b)


(a, b) = map(int, input().split())
k = b - a
print(sum(range(k)) - a)


(a, b) = map(int, input().split())
t = a - b
print((t * t - t) // 2 - b)


(a, b) = map(int, input().split())
c = b - a
d = c * (c - 1) // 2
print(d - a)


(a, b) = list(map(int, input().split()))
c = b - a - 1
res = c * (c + 1) // 2 - a
print(res)


def Gauss_sum(n):
	return n * (n + 1) // 2
(a, b) = map(int, input().split())
for i in range(999):
	if Gauss_sum(i + 1) - a == Gauss_sum(i + 2) - b:
		print(Gauss_sum(i + 1) - a)
		break


(a, b) = list(map(int, input().split()))
numbers = []
for i in range(1, 1000):
	numbers.append(i)
steel_towers = []
for i in range(999):
	steel_towers.append(sum(numbers[:i + 1]))
print(steel_towers[b - a - 1] - b)


(a, b) = map(int, input().split())
x = b - a
s = 0
for i in range(1, x, 1):
	s += i
ans = s - a
print(ans)


(a, b) = map(int, input().split())
x = b - a
c = (1 + x) * x // 2
print(c - b)


def fallen_snow(a, b):
	return (b - a) * (b - a + 1) // 2 - b

def main():
	(a, b) = map(int, input().split())
	print(fallen_snow(a, b))

def __starting_point():
	main()
__starting_point()


(a, b) = map(int, input().split())
print(sum([x for x in range(b - a)]) - a)


(A, B) = map(int, input().split())
S = B - A
print(S * (S + 1) // 2 - B)


(a, b) = map(int, input().split())
n = b - a
n = round(n * (n + 1) / 2)
print(n - b)


(a, b) = map(int, input().split())
dif = b - a
temp = 0
for i in range(dif):
	temp += i
ans = temp - a
print(ans)


def main():
	(a, b) = list(map(int, input().split()))
	diff = b - a
	high_a = sum(list(range(1, diff)))
	print(high_a - a)

def __starting_point():
	main()
__starting_point()


(a, b) = map(int, input().split())
k = sum(list(range(1, b - a)))
print(k - a)


(A, B) = map(int, input().split())
N = B - A
X = N * (N + 1) // 2
print(X - B)


(a, b) = map(int, input().split())
c = b - a
for i in range(1, 999):
	x = (i + 1) * i // 2
	y = (i + 2) * (i + 1) // 2
	if y - x == c:
		print(x - a)
		break


(A, B) = map(int, input().split())
d = B - A
s = sum([x for x in range(1, d)])
print(s - A)


(a, b) = list(map(int, input().split()))
x = b - a
tower = 0
for i in range(1, x + 1):
	tower += i
print(tower - b)


(a, b) = [int(i) for i in input().split()]
print((b - a + 1) * (b - a) // 2 - b)


(a, b) = map(int, input().split())
d = b - a
print(-~d * d // 2 - b)


def n_sum(n):
	myList = [int(i) for i in range(1, n + 1)]
	return sum(myList)
(a, b) = map(int, input().split())
print(n_sum(b - a) - b)


(a, b) = map(int, input().split())
n = b - a
s = n * (n + 1) // 2
print(s - b)


(a, b) = map(int, input().split())
total = 0
for i in range(1, b - a + 1):
	total += i
print(total - b)


(a, b) = map(int, input().split())
d = b - a
r = d * (d + 1) // 2 - b
print(r)


import sys
stdin = sys.stdin

def ns():
	return stdin.readline().rstrip()

def ni():
	return int(stdin.readline().rstrip())

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

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

def main():
	(a, b) = nm()
	print(sum(range(1, b - a)) - a)

def __starting_point():
	main()
__starting_point()


(a, b) = list(map(int, input().split()))
x = b - a
print(x * (x + 1) // 2 - b)


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


(a, b) = map(int, input().split())
d = b - a
s = (d + 1) * d // 2
ans = s - b
print(ans)


ab = list([int(x) for x in input().split(' ')])
a = ab[0]
b = ab[1]
n = b - a - 1
x = n * (n + 1) // 2 - a
print(x)


(a, b) = map(int, input().split())
k = b - a
print(-~k * k // 2 - b)


(a, b) = list(map(int, input().split()))
tmp = 1
for i in range(2, 1000):
	if i == b - a:
		print(tmp - a)
	tmp += i


(a, b) = map(int, input().split())
difference = b - a
answer = 0
for x in range(difference):
	answer += x
print(answer - a)


(a, b) = list(map(int, input().split(' ')))
i = b - a
print(i * (i - 1) // 2 - a)


(a, b) = map(int, input().split())
n = b - a
ah = n * (n - 1) // 2
print(ah - a)


(n, m) = list(map(int, input().split()))
bt = sum([i for i in range(1, m - n + 1)])
print(bt - m)


(a, b) = map(int, input().split())
n = b - a
B = (1 + n) * n // 2
print(B - b)


(a, b) = map(int, input().split())
i = b - a
h = i * (i + 1) // 2
print(h - b)


(a, b) = map(int, input().split())
m = b - a
t = 0
for i in range(m):
	t += i
print(t - a)


(a, b) = map(int, input().split())
tower_height = 0
tower_height_list = []
for i in range(1, 999 + 1):
	tower_height += i
	tower_height_list.append(tower_height)
	i += 1
for i in range(len(tower_height_list)):
	if tower_height_list[i] - b == tower_height_list[i - 1] - a:
		print(tower_height_list[i] - b)


[a, b] = list(map(int, input().split()))
d = b - a
print(d * (d + 1) // 2 - b)


(a, b) = list(map(int, input().split()))
N = b - a
print(N * (N + 1) // 2 - b)


(a, b) = map(int, input().split())
c = b - a
t = int(c * (2 + (c - 1)) / 2)
print(t - b)


(a, b) = map(int, input().split())
n = b - a
print(int(0.5 * n * (n + 1) - b))


(a, b) = map(int, input().split())
n = b - a
c = (1 + n) * n // 2
print(c - b)


(a, b) = map(int, input().split())
k = b - a - 1
l = k * (k + 1) / 2
print(int(l - a))


(a, b) = map(int, input().split())
x = 0
for i in range(b - a):
	x += i
print(x - a)


(a, b) = map(int, input().split())
n = b - a
bl = n * (n + 1) // 2
print(bl - b)


(a, b) = map(int, input().split())
n = b - a
ans = n * (n + 1) // 2 - b
print(ans)


import sys
lines = [s.rstrip('\n') for s in sys.stdin.readlines()]
(a, b) = [int(num) for num in lines.pop(0).split(' ')]
dif = b - a
height = dif * (dif - 1) // 2
print(height - a)


(a, b) = map(int, input().split())
k = b - a
sum = 0
print(int(k * (k + 1) / 2 - b))


(a, b) = map(int, input().split())
n = b - a
sum = 0
for i in range(1, n + 1):
	sum += i
print(sum - b)


(a, b) = list(map(int, input().split()))
x = 0
for i in range(1000):
	x += i
	y = x - i
	if a - y == b - x:
		print(y - a)


(a, b) = map(int, input().split())
c = b - a
ans = int(c * (c + 1) / 2 - b)
print(ans)


(a, b) = map(int, input().split())
M = sum(range(b - a))
print(M - a)


(a, b) = map(int, input().split())
n = b - a
sumn = n * (n + 1) // 2
print(sumn - b)


(a, b) = map(int, input().split())
n = b - a
m = n * (n + 1) // 2
print(int(m - b))


(a, b) = map(int, input().split())
print(sum((_ for _ in range(b - a + 1))) - b)


(a, b) = map(int, input().split())
c = b - a
h = c * (c + 1) // 2
print(h - b)


(a, b) = map(int, input().split())
n = b - a
h = n * (n + 1) // 2 - b
print(h)


(a, b) = map(int, input().split())
n = b - a
S = n * (n + 1) // 2 - b
print(S)


(a, b) = list(map(int, input().split()))
s = b - a
tall = 0
for i in range(1, s):
	tall += i
print(tall - a)


def answer(a: int, b: int) -> int:
	return sum(range(1, b - a + 1)) - b

def main():
	(a, b) = list(map(int, input().split()))
	print(answer(a, b))

def __starting_point():
	main()
__starting_point()


(a, b) = map(int, input().split())
be = b - a
bh = (1 + be) * be // 2
print(bh - b)


from itertools import accumulate
import sys
(a, b) = map(int, input().split())
n = 500000
l = []
for i in range(n):
	l.append(i)
	tmp = sum(l)
	if abs(abs(a + tmp) - abs(b + tmp)) == i:
		print(tmp - b)
		return


(A, B) = map(int, input().split())
C = sum(list(range(B - A)))
print(C - A)


(a, b) = map(int, input().split())
diff = b - a
sum = 0
for i in range(1, diff, 1):
	sum += i
ans = sum - a
print(ans)


(a, b) = map(int, input().split())
c = b - a
n = 0
for i in range(1, 999 + 1):
	n += i
	if c == i:
		ans = n - b
print(ans)


(n, m) = map(int, input().split())
a = sum(range(m - n))
print(a - n)


(n, m) = [int(x) for x in input().split()]

def su(p):
	c = 0
	for i in range(p + 1):
		c += i
	return c
l = m - n
print(su(l - 1) - n)


(N, M) = map(int, input().split())
K = M - N
from functools import reduce
from operator import add
NL = reduce(add, range(1, K))
ans = NL - N
print(ans)


(a, b) = map(int, input().split())
N = b - a
print(sum(list(range(1, N + 1))) - b)


(a, b) = list(map(int, input().split()))
diff = b - a
x = 1
y = 3
i = 3
while True:
	if y - x == diff:
		break
	x = y
	y = y + i
	i = i + 1
print(y - b)


(a, b) = map(int, input().split())
c = b - a
ha = c * (c - 1) // 2
print(ha - a)


(a, b) = list(map(int, input().split()))
for n in range(0, 1000):
	west = n * (n - 1) / 2 - a
	east = n * (n + 1) / 2 - b
	if west == east:
		print(int(east))
		return


(a, b) = list(map(int, input().split()))
height = 0
for i in range(b - a):
	height += i + 1
print(height - b)


(a, b) = map(int, input().split())
A = []
c = 1
for i in range(2, 1001):
	A.append(c)
	c += i
d = b - a
print(A[d - 2] - a)


(a, b) = map(int, input().split())
k = b - a - 1
ans = k * (k + 1) // 2 - a
print(ans)


lst = input().split()
a = int(lst[0])
b = int(lst[1])
d = b - a
print(sum(range(1, d + 1)) - b)


(A, B) = map(int, input().split())
res = (B - A) * (B - A - 1) // 2 - A
print(res)


(x, y) = map(int, input().split())
a = y - x
b = a * (a - 1) / 2
print(round(b - x))


(a, b) = map(int, input().split())
n = b - a
print((n * n + n) // 2 - b)


(a, b) = map(int, input().split())
n = b - a
print(int(n * (n + 1) / 2.0) - b)


a = list(map(int, input().split()))
h = 0
p = 1
li = []
for i in range(999):
	h += p
	p += 1
	li.append(h)
for i in range(len(li)):
	for k in range(len(li)):
		if a[0] - li[i] == a[1] - li[k] and k == i + 1:
			print(abs(a[0] - li[i]))


(a, b) = map(int, input().split())
x = b - a
wa = (x ** 2 + x) // 2
print(wa - b)