Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input()
N = len(S)

counter = 0
surplus = [0]*2019
surplus[0] += 1

for i in range(N):
    surplus[int(S[i:]) % 2019] += 1

print(sum([i*(i-1)//2 for i in surplus]))


Fixed submission:
# -*- coding: utf-8 -*-

surplus = [0]*2019
surplus[0] += 1

d = 1
n = 0
for i in reversed(input()):
    n = (n + int(i)*d) %2019
    d = d*10 % 2019
    surplus[n] += 1

print(sum([i*(i-1)//2 for i in surplus]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input()
N = len(S)

counter = 0
surplus = [0]*2019
surplus[0] += 1

for i in range(N):
    surplus[int(S[i:]) % 2019] += 1

print(sum([i*(i-1)//2 for i in surplus]))


Fixed submission:
# -*- coding: utf-8 -*-

surplus = [0]*2019
surplus[0] += 1

d = 1
n = 0
for i in reversed(input()):
    n = (n + int(i)*d) %2019
    d = d*10 % 2019
    surplus[n] += 1

print(sum([i*(i-1)//2 for i in surplus]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input()
N = len(S)

counter = 0
surplus = [0]*2019
surplus[0] += 1

for i in range(N):
    surplus[int(S[i:]) % 2019] += 1
#print(surplus)
for x in surplus:
    if x >= 2:
        counter += int(x*(x-1)/2)

print(counter)


Fixed submission:
# -*- coding: utf-8 -*-

surplus = [0]*2019
surplus[0] += 1

d = 1
n = 0
for i in reversed(input()):
    n = (n + int(i)*d) %2019
    d = d*10 % 2019
    surplus[n] += 1

print(sum([i*(i-1)//2 for i in surplus]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input()
N = len(S)

counter = 0
surplus = [0]*2019
surplus[0] += 1

for i in range(N):
    surplus[int(S[i:]) % 2019] += 1
#print(surplus)
for x in surplus:
    if x >= 2:
        counter += int(x*(x-1)/2)

print(counter)


Fixed submission:
# -*- coding: utf-8 -*-

surplus = [0]*2019
surplus[0] += 1

d = 1
n = 0
for i in reversed(input()):
    n = (n + int(i)*d) %2019
    d = d*10 % 2019
    surplus[n] += 1

print(sum([i*(i-1)//2 for i in surplus]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input()
N = len(S)
"""
L4 = []
L5 = []
L6 = []
L7 = []
L8 = []
for i in range(10000):
    t = len(str(i*2019))
    if t == 4:
        L4.append(i*2019)
    if t == 5:
        L5.append(i*2019)
    if t == 6:
        L6.append(i*2019)
    if t == 7:
        L7.append(i*2019)
    if t == 8:
        L8.append(i*2019)
#print(len(L4),len(L5),len(L6),len(L7))

"""
counter = 0

for i in range(N-3):
    #j = 4
    #while (j < N+1-i):
    M = min(9,N+1-i)
    for j in range(4,M):
        if int(S[i:i+j]) % 2019 == 0:
            counter += 1
            for k in range(j+1,N+1-i):
                if int(S[i:i+k]) % 2019 == 0:
                    counter += 1
print(counter)


Fixed submission:
# -*- coding: utf-8 -*-

surplus = [0]*2019
surplus[0] += 1

d = 1
n = 0
for i in reversed(input()):
    n = (n + int(i)*d) %2019
    d = d*10 % 2019
    surplus[n] += 1

print(sum([i*(i-1)//2 for i in surplus]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

S = input()
N = len(S)
counter = 0
for i in range(N-3):
    for j in range(4,N+1-i):
        #print(i,j)
        if int(S[i:i+j]) % 2019 == 0:
            #print(S[i:i+j],i,j)
            counter += 1
print(counter)


Fixed submission:
# -*- coding: utf-8 -*-

surplus = [0]*2019
surplus[0] += 1

d = 1
n = 0
for i in reversed(input()):
    n = (n + int(i)*d) %2019
    d = d*10 % 2019
    surplus[n] += 1

print(sum([i*(i-1)//2 for i in surplus]))