number = str(eval(input()))[::-1]

remainderDictionary = {0: 1}

    

sum = 0

x = 1

for i in number:

  x = (x * 10) % 2019

  sum = (sum + int(i) * x) % 2019 

  remainderValue = remainderDictionary.get(sum,0) + 1

  remainderDictionary[sum] = remainderValue

     

ans = 0

for i in remainderDictionary:

  value = remainderDictionary[i]

  ans += value * (value - 1) // 2 # N C 2

print(ans)
number = str(eval(input()))[::-1]

remainderDictionary = {0: 1}



digitDictionary = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}



sum = 0

x = 1

for i in number:

  x = (x * 10) % 2019

  sum = (sum + digitDictionary[i] * x) % 2019 

  remainderValue = remainderDictionary.get(sum,0) + 1

  remainderDictionary[sum] = remainderValue

     

ans = 0

for i in remainderDictionary:

  value = remainderDictionary[i]

  ans += value * (value - 1) // 2 # N C 2

print(ans)
number = str(eval(input()))[::-1]
remainderDictionary = {0: 1}
sum = 0
x = 1
for i in number:
    x = (x * 10) % 2019
    sum = (sum + int(i) * x) % 2019
    remainderValue = remainderDictionary.get(sum, 0) + 1
    remainderDictionary[sum] = remainderValue
ans = 0
for i in remainderDictionary:
    value = remainderDictionary[i]
    ans += value * (value - 1) // 2  # N C 2
print(ans)

number = str(eval(input()))[::-1]
remainderDictionary = {0: 1}
digitDictionary = {
    "0": 0,
    "1": 1,
    "2": 2,
    "3": 3,
    "4": 4,
    "5": 5,
    "6": 6,
    "7": 7,
    "8": 8,
    "9": 9,
}
sum = 0
x = 1
for i in number:
    x = (x * 10) % 2019
    sum = (sum + digitDictionary[i] * x) % 2019
    remainderValue = remainderDictionary.get(sum, 0) + 1
    remainderDictionary[sum] = remainderValue
ans = 0
for i in remainderDictionary:
    value = remainderDictionary[i]
    ans += value * (value - 1) // 2  # N C 2
print(ans)

+digitDictionary = { +    "0": 0, +    "1": 1, +    "2": 2, +    "3": 3, +    "4": 4, +    "5": 5, +    "6": 6, +    "7": 7, +    "8": 8, +    "9": 9, +} -    sum = (sum + int(i) * x) % 2019 +    sum = (sum + digitDictionary[i] * x) % 2019