S = input().strip()

A = [0 for _ in range(len(S))]

A[-1] = int(S[-1])%3

for i in range(2,len(S)+1):

    A[-i] = (A[-i+1]+int(S[-i]))%3

B = [0 for _ in range(len(S))]

B[-1] = int(S[-1])%673

a = 1

for i in range(2,len(S)+1):

    a = (a*10)%673

    B[-i] = (int(S[-i])*a+B[-i+1])%673

C = {}

for i in range(len(S)):

    a = A[i]

    b = B[i]

    if (a,b) not in C:

        C[(a,b)] = 0

    C[(a,b)] += 1

if (0,0) in C:

    C[(0,0)] += 1

cnt = 0

for c in C:

    n = C[c]

    cnt += (n*(n-1))//2

print(cnt)
S = input().strip()

N = len(S)

A = [0 for _ in range(N)]

B = [0 for _ in range(N)]

B[0] = 1

for i in range(1,N):

    B[i] = (B[i-1]*10)%2019

a = 0

for i in range(N-1,-1,-1):

    a = (int(S[i])*B[N-1-i]+a)%2019

    A[i] = a

C = {i:0 for i in range(2019)}

for i in range(N):

    C[A[i]] += 1

cnt = C[0]

for i in range(2019):

    cnt += (C[i]*(C[i]-1))//2

print(cnt)
S = input().strip()
A = [0 for _ in range(len(S))]
A[-1] = int(S[-1]) % 3
for i in range(2, len(S) + 1):
    A[-i] = (A[-i + 1] + int(S[-i])) % 3
B = [0 for _ in range(len(S))]
B[-1] = int(S[-1]) % 673
a = 1
for i in range(2, len(S) + 1):
    a = (a * 10) % 673
    B[-i] = (int(S[-i]) * a + B[-i + 1]) % 673
C = {}
for i in range(len(S)):
    a = A[i]
    b = B[i]
    if (a, b) not in C:
        C[(a, b)] = 0
    C[(a, b)] += 1
if (0, 0) in C:
    C[(0, 0)] += 1
cnt = 0
for c in C:
    n = C[c]
    cnt += (n * (n - 1)) // 2
print(cnt)

S = input().strip()
N = len(S)
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
B[0] = 1
for i in range(1, N):
    B[i] = (B[i - 1] * 10) % 2019
a = 0
for i in range(N - 1, -1, -1):
    a = (int(S[i]) * B[N - 1 - i] + a) % 2019
    A[i] = a
C = {i: 0 for i in range(2019)}
for i in range(N):
    C[A[i]] += 1
cnt = C[0]
for i in range(2019):
    cnt += (C[i] * (C[i] - 1)) // 2
print(cnt)

-A = [0 for _ in range(len(S))] -A[-1] = int(S[-1]) % 3 -for i in range(2, len(S) + 1): -    A[-i] = (A[-i + 1] + int(S[-i])) % 3 -B = [0 for _ in range(len(S))] -B[-1] = int(S[-1]) % 673 -a = 1 -for i in range(2, len(S) + 1): -    a = (a * 10) % 673 -    B[-i] = (int(S[-i]) * a + B[-i + 1]) % 673 -C = {} -for i in range(len(S)): -    a = A[i] -    b = B[i] -    if (a, b) not in C: -        C[(a, b)] = 0 -    C[(a, b)] += 1 -if (0, 0) in C: -    C[(0, 0)] += 1 -cnt = 0 -for c in C: -    n = C[c] -    cnt += (n * (n - 1)) // 2 +N = len(S) +A = [0 for _ in range(N)] +B = [0 for _ in range(N)] +B[0] = 1 +for i in range(1, N): +    B[i] = (B[i - 1] * 10) % 2019 +a = 0 +for i in range(N - 1, -1, -1): +    a = (int(S[i]) * B[N - 1 - i] + a) % 2019 +    A[i] = a +C = {i: 0 for i in range(2019)} +for i in range(N): +    C[A[i]] += 1 +cnt = C[0] +for i in range(2019): +    cnt += (C[i] * (C[i] - 1)) // 2