S = list(str(eval(input())))

S = [int(s) for s in S]

n = len(S)



S.reverse()



def power(a, n, mod):

  bi=str(format(n,"b")) #2進数

  res=1

  for i in range(len(bi)):

    res=(res*res) %mod

    if bi[i]=="1":

      res=(res*a) %mod

  return res



cum1 = [-1]*(n+1)

cum1[0] = 0

for i in range(n):

    temp = cum1[i]+S[i]*power(10, i, 673)

    cum1[i+1] = temp%673

#print(cum1)



cum2 = [-1]*(n+1)

cum2[0] = 0

for i in range(n):

    temp = cum2[i]+S[i]*power(10, i, 3)

    cum2[i+1] = temp%3

#print(cum2)



d = {}

ans = 0

for i in range(n+1):

    c1 = cum1[i]

    c2 = cum2[i]

    if (c1, c2) in d:

        ans += d[(c1, c2)]

        d[(c1, c2)] += 1

    else:

        d[(c1, c2)] = 1

print(ans)

s =list(str(eval(input())))

s = [int(c) for c in s]

s.reverse()



n = len(s)

p = 2019



def power(a, n, mod):

  bi=str(format(n,"b")) #2進数

  res=1

  for i in range(len(bi)):

    res=(res*res) %mod

    if bi[i]=="1":

      res=(res*a) %mod

  return res



temp = 0

cum = [0]*n

for i in range(n):

    temp += s[i]*power(10, i, p)

    temp = temp%p

    cum[i] = temp

cum = [0]+cum



#print(cum)



d = {}

ans = 0

for i in range(n+1):

  if cum[i] not in d:

    d[cum[i]] = 1

  else:

    ans += d[cum[i]]

    d[cum[i]] += 1

print(ans)

S = list(str(eval(input())))
S = [int(s) for s in S]
n = len(S)
S.reverse()


def power(a, n, mod):
    bi = str(format(n, "b"))  # 2進数
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == "1":
            res = (res * a) % mod
    return res


cum1 = [-1] * (n + 1)
cum1[0] = 0
for i in range(n):
    temp = cum1[i] + S[i] * power(10, i, 673)
    cum1[i + 1] = temp % 673
# print(cum1)
cum2 = [-1] * (n + 1)
cum2[0] = 0
for i in range(n):
    temp = cum2[i] + S[i] * power(10, i, 3)
    cum2[i + 1] = temp % 3
# print(cum2)
d = {}
ans = 0
for i in range(n + 1):
    c1 = cum1[i]
    c2 = cum2[i]
    if (c1, c2) in d:
        ans += d[(c1, c2)]
        d[(c1, c2)] += 1
    else:
        d[(c1, c2)] = 1
print(ans)

s = list(str(eval(input())))
s = [int(c) for c in s]
s.reverse()
n = len(s)
p = 2019


def power(a, n, mod):
    bi = str(format(n, "b"))  # 2進数
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == "1":
            res = (res * a) % mod
    return res


temp = 0
cum = [0] * n
for i in range(n):
    temp += s[i] * power(10, i, p)
    temp = temp % p
    cum[i] = temp
cum = [0] + cum
# print(cum)
d = {}
ans = 0
for i in range(n + 1):
    if cum[i] not in d:
        d[cum[i]] = 1
    else:
        ans += d[cum[i]]
        d[cum[i]] += 1
print(ans)

-S = list(str(eval(input()))) -S = [int(s) for s in S] -n = len(S) -S.reverse() +s = list(str(eval(input()))) +s = [int(c) for c in s] +s.reverse() +n = len(s) +p = 2019 -cum1 = [-1] * (n + 1) -cum1[0] = 0 +temp = 0 +cum = [0] * n -    temp = cum1[i] + S[i] * power(10, i, 673) -    cum1[i + 1] = temp % 673 -# print(cum1) -cum2 = [-1] * (n + 1) -cum2[0] = 0 -for i in range(n): -    temp = cum2[i] + S[i] * power(10, i, 3) -    cum2[i + 1] = temp % 3 -# print(cum2) +    temp += s[i] * power(10, i, p) +    temp = temp % p +    cum[i] = temp +cum = [0] + cum +# print(cum) -    c1 = cum1[i] -    c2 = cum2[i] -    if (c1, c2) in d: -        ans += d[(c1, c2)] -        d[(c1, c2)] += 1 +    if cum[i] not in d: +        d[cum[i]] = 1 -        d[(c1, c2)] = 1 +        ans += d[cum[i]] +        d[cum[i]] += 1