Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = s[::-1]

L = [0]
for i in range(len(s)):
    L.append((L[-1]+(int(s[i])*10**i)%2019)%2019)

D = dict()
for j in L:
    if j in D:
        D[j] += 1
    else:
        D[j] = 1
ans = 0
for k in D.values():
    ans += k * (k-1) //2

print(ans)

Fixed submission:
s = input()
n = len(s)

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

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    t *= 10
    t %= 2019
    memo[num] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

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

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    memo[num] += 1
    t *= 10

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Fixed submission:
s = input()
n = len(s)

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

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    t *= 10
    t %= 2019
    memo[num] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

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

num = 0
ten = 1
for i in reversed(s):
    num += int(i) * ten
    memo[num%2019] += 1
    ten *= 10

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Fixed submission:
s = input()
n = len(s)

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

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    t *= 10
    t %= 2019
    memo[num] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
s = s[::-1]

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

num = 0
ten = 1
for i in s:
    num += int(i) * ten
    memo[num%2019] += 1
    ten *= 10

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Fixed submission:
s = input()
n = len(s)

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

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    t *= 10
    t %= 2019
    memo[num] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

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

num = 0
ten = 1
for i in range(n):
    num += int(s[-(i+1)]) * ten
    memo[num%2019] += 1
    ten *= 10

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Fixed submission:
s = input()
n = len(s)

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

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    t *= 10
    t %= 2019
    memo[num] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

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

num = ""
for i in range(n):
    num = s[-(i+1)] + num
    num_int = int(num)
    memo[num_int%2019] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Fixed submission:
s = input()
n = len(s)

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

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    t *= 10
    t %= 2019
    memo[num] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)

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

num = ""
for i in range(n):
    num = s[-(i+1)] + num
    num_int = int(num)
    memo[num_int%2019] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)

Fixed submission:
s = input()
n = len(s)

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

num = 0
t = 1
for i in reversed(s):
    num += int(i) * t
    num %= 2019
    t *= 10
    t %= 2019
    memo[num] += 1

ans = 0
for p in memo:
    ans += p*(p-1)//2

print(ans)