Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
h = [int(x) for x in list(S)]
N = len(h)
a = [0] * 2019
a[0] = 1
T = 0
r = 1
c = 0
for i in range(N-1, -1, -1):
    T = T + h[i] * r
    q = T % 2019
    r = r * 10
    c += a[q]
    a[q] += 1
print(c)

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
h = [int(x) for x in list(S)]
N = len(h)
a = [0] * 2019
a[0] = 1
T = 0
r = 1
c = 0
for i in range(N-1, -1, -1):
    T = T + h[i] * r
    r = r * 10
    c += a[T%2019]
    a[T%2019] += 1
print(c)

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
S = str(input())
N = len(h)
a = [0] * 2019
a[0] = 1
T = 0
r = 1
c = 0
for i in range(N-1, -1, -1):
    T = T + int(S[i]) * r
    r = r * 10
    c += a[T%2019]
    a[T%2019] += 1
print(c)

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
N = len(h)
a = [0] * 2019
a[0] = 1
T = 0
r = 1
c = 0
for i in range(N-1, -1, -1):
    T = T + int(S[i]) * r
    r = r * 10
    c += a[T%2019]
    a[T%2019] += 1
print(c)

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
N = len(h)
a = [0] * 2019
a[0] = 1
T = 0
r = 1
c = 0
for i in range(N-1, -1, -1):
    T = T + int(S[i]) * r
    r = r * 10
    c += a[T%2019]
    a[T%2019] += 1
print(c)

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
h = [int(x) for x in list(S)]
N = len(h)
a = [0] * 2019
a[0] = 1
T = 0
r = 1
c = 0
for i in range(N-1, -1, -1):
    T = T + h[i] * r
    r = r * 10
    c += a[T%2019]
    a[T%2019] += 1
print(c)

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
h = [int(x) for x in list(S)]
N = len(h)
a = []
T = 0
r = 1
for i in range(N-1, -1, -1):
    T = T + h[i] * r
    r = r * 10
    a.append(T%2019)
b = []
for j in range(0, N):
    if a[j] not in b:
        b.append(a[j])
c = 0
for k in range(0, len(b)):
    d = a.count(b[k])
    c += d * (d-1) /2
c += a.count(0)
print(int(c))

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
h = [int(x) for x in list(S)]
N = len(h)
c = 0
for i in range(0, N+1):
    for j in range(i, N+1):
        b = 0
        for k in range(i, j):
            b = b * 10 + h[k]
        if b != 0 and b % 2019 == 0:
            c += 1
print(c)

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
h = [int(x) for x in list(S)]
N = len(h)
a = []
for i in range(0, N+1):
    for j in range(i, N+1):
        b = 0
        for k in range(i, j):
            b = b * 10 + h[k]
        a.append(b)
c = 0
for m in range(0, len(a)):
    if a[m] != 0 and a[m] % 2019 == 0:
        c += 1
print(c)

Fixed submission:
S = input()
P = 2019
N = len(S)
num = [0] * P
num[0] = 1
c = 0
ans = 0
dgt = 1
for i in range(N-1, -1, -1):
    c = (c + int(S[i]) * dgt) % P
    dgt *= 10
    dgt %= P
    ans += num[c]
    num[c] += 1

print(ans)