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

for i in reversed(range(1, n)):
	for j in range(i):
		a[j] = min(a[j], a[i] - 1 if a[i] > 0 else 0)

print(sum(a))

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

watermark = a[-1]
for i in reversed(range(n - 1)):
	if a[i] < watermark:
		watermark = a[i]
	else:
		a[i] = max(watermark - 1, 0)
		watermark = a[i]

print(sum(a))

solve in O(n) using watermark