Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in reversed(A):
    S += int(n)*d
    S %= 2019
    lis[S] += 1
    d *= 10

result = 0

for n in lis:
    result += (n*(n-1)//2)


print(result)


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in reversed(A):
    S += int(n)*d
    sm = S % 2019
    lis[sm] += 1
    d *= 10

result = 0

for n in lis:
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in range(1, l):
    S += (int(A[-n])*d)
    sm = S % 2019
    lis[sm] += 1
    d *= 10

result = 0

for n in lis:
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1

for n in range(1, l):
    S += (int(A[-n])*(10**(n-1)))
    sm = S % 2019
    lis[sm] += 1

result = 0

for n in lis:
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = 0
dic = {i: 0 for i in range(2019)}
dic[0] += 1
l = len(A)+1

for n in range(1, l):
    S += (int(A[-n])*(10**(n-1)))
    sm = S % 2019
    dic[sm] += 1

result = 0

for n in dic.values():
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = 0
dic = {0:1}

for n in range(1, len(A)+1):
    S += (int(A[-n])*(10**(n-1)))
    sm = S % 2019
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for n in dic.values():
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = [0]
dic = {0:1}

for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))
    sm = S[-1] % 2019
    S.pop(0)
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for n in dic.values():
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = [0]
dic = {0:1}

for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))
    sm = S[-1] % 2019
    S.pop(0)
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for num in dic:
    n = dic[num]
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = [0]
dic = {0:1}

for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))
    sm = S[-1] % 2019
    if sm in dic:
        dic[sm] += 1
    else:
        dic[sm] = 1

result = 0

for num in dic:
    n = dic[num]
    result += (n*(n-1)/2)


print(int(result))


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = input()

S = [0]


for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))

result = 0

for i in range(len(S)):
    i = i + 1
    for j in range(len(S)-i):
        if S[-i] == S[-j]:
            continue
        if (S[-i] - S[j]) % 2019 == 0:
            result += 1


print(result)


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A = list(input())

S = [0]


for n in range(1, len(A)+1):
    S.append(S[-1] + (int(A[-n])*(10**(n-1))))

result = 0

for i in range(len(S)):
    i = i + 1
    for j in range(len(S)-i):
        if S[-i] == S[-j]:
            continue
        if (S[-i] - S[j]) % 2019 == 0:
            result += 1


print(result)


Fixed submission:
S = input()
 
res = [0] * 2019
res[0] = 1
 
d = 1
a = 0
 
for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019
 
ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)