lis = []
for i in range(5): lis.append(input())
a, b = lis[1: 3]
a=a.strip()
b=b.strip()
def calc(x,y,z):
sb=0
if z>0:
if x<y:
y-=1
cnt=(y-x)//z+1
sb=(x+x+z*(cnt-1))*cnt//2
else:
if x>y:
y+=1
cnt=(x-y)//(-z)+1
sb=(x+x+z*(cnt-1))*cnt//2
return sb
la = a[a.index('(')+1: a.index(')')]
lb = b[b.index('(')+1: b.index(')')]
la = la.split(',')
lb = lb.split(',')
ans=0
for i in range(*map(int,la)):
def dec(s):
if s==a[4]:
return i
else:
return int(s)
x=dec(lb[0])
y=dec(lb[1])
if len(lb)==2:
z=1
else:
z=dec(lb[2])
ans+=calc(x,y,z)
print(ans)