Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
for i in range(l):
    dp = dp + pow(10,i)*int(S[-1-i])
    mod[dp % 2019] += 1
mod[0] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
for i in range(l):
    dp = dp + pow(10,i)*int(S[-1-i])
    mod[dp % 2019] += 1
mod[0] += 1
cnt = 0
for i in range(2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
l = len(S)
dp = int(S[-1])
suml = [dp]
for i in range(l-1):
    dp = dp + pow(10,(i+1))*int(S[-2-i])
    suml.append(dp % 2019)
mod = {0:1}
for a in suml:
    if a in mod.keys():
        mod[a] += 1
    else:
        mod[a] = 1
cnt = 0
for a in mod:
    if mod[a] > 1:
        cnt += (mod[a]*(mod[a]-1))//2
print(cnt)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
listS = list(str(S))
l = len(listS)
dp = int(listS[-1])
suml = [dp]
for i in range(l-1):
    dp = dp + pow(10,(i+1))*int(listS[-2-i])
    suml.append(dp % 2019)
mod = {0:1}
for a in suml:
    if a in mod.keys():
        mod[a] += 1
    else:
        mod[a] = 1
cnt = 0
for a in mod:
    if mod[a] > 1:
        cnt += (mod[a]*(mod[a]-1))//2
print(cnt)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
listS = list(str(S))
l = len(listS)
dp = int(listS[-1])
suml = [dp]
for i in range(l-1):
    dp = dp + (10**(i+1))*int(listS[-2-i])
    suml.append(dp % 2019)
mod = {0:1}
for a in suml:
    if a in mod.keys():
        mod[a] += 1
    else:
        mod[a] = 1
cnt = 0
for a in mod:
    if mod[a] > 1:
        cnt += (mod[a]*(mod[a]-1))//2
print(cnt)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
listS = list(str(S))
l = len(listS)
dp = int(listS[-1])
suml = [dp]
mod = [0]
for i in range(l-1):
    dp = dp + (10**(i+1))*int(listS[-2-i])
    suml.append(dp)
for a in suml:
    mod.append(a % 2019)
cnt = 0
for i in range(2019):
    if mod.count(i) > 1:
        cnt += ((mod.count(i))*(mod.count(i)-1))//2
print(cnt)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
listS = list(str(S))
l = len(listS)
cnt = 0
suml = [0]
for i in range(l):
    suml.append(int("".join(map(str, listS[l-i-1:l+1]))))
mod = []
for a in suml:
    mod.append(a % 2019)
for i in range(2019):
    if mod.count(i) > 1:
        cnt += ((mod.count(i))*(mod.count(i)-1))//2
print(cnt)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
listS = list(str(S))
count = 0
for i in range(len(listS)-3):
    for j in range(len(listS)-3-i):
        if int("".join(map(str, listS[j:j+4+i]))) % 2019 == 0:
            count += 1
print(count)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
listS = list(str(S))
count = 0
for i in range(len(listS)-3):
    for j in range(len(listS)-3-i):
        if int("".join(map(str, listS[j:j+4+i]))) % 2019 == 0:
            count += 1
print(count)

Fixed submission:
S = str(input())
l = len(S)
mod = [0] * 2019
dp = 0
pw = 1
for i in range(l):
    mod[dp % 2019] += 1
    dp = dp + pw * int(S[-1-i])
    pw = (pw * 10) % 2019
mod[dp % 2019] += 1
cnt = 0
for i in range(2019):
    cnt += (mod[i]*(mod[i]-1))//2
print(cnt)