Buggy python submission (verdict: Time Limit Exceeded):
#S = input()
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10

for v in mods:
    count = count + v*(v-1)//2

print(count)


Fixed submission:
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10
    x = x % 2019

for v in mods:
    count = count + v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reversed(S):
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10

for v in mods:
    count = count + v*(v-1)//2

print(count)


Fixed submission:
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10
    x = x % 2019

for v in mods:
    count = count + v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)
count = 0
T = [0] * (n + 1)
mod = 0
x = 1
mod_dict = {i:0 for i in range(2019)}
mod_dict[0] = 1
for s in reversed(S):
    mod = (mod + (int(s) * x)) % 2019
    mod_dict[mod] = mod_dict[mod] + 1
    x = x * 10

count = 0
for k, v in mod_dict.items():
    count = count + v*(v-1)//2

print(count)


Fixed submission:
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10
    x = x % 2019

for v in mods:
    count = count + v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)
count = 0
T = [0] * (n + 1)
mods = [0] * (n + 1)
mod_dict = {i:0 for i in range(2019)}
mod_dict[0] = 1
for i in reversed(range(n)):
    mods[i] = (mods[i+1] + (int(S[i]) * (10 ** (n - i -1)))) % 2019
    mod_dict[mods[i]] = mod_dict[mods[i]] + 1

count = 0
for k, v in mod_dict.items():
    count = count + int(v*(v-1)/2)

print(count)


Fixed submission:
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10
    x = x % 2019

for v in mods:
    count = count + v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)
count = 0
T = [0] * (n + 1)
mod_dict = {0:0}
count  = 0
for i in reversed(range(n)):
    #print(i)
    T[i] = T[i+1] + int(S[i]) * (10 ** (n - i - 1))
    # print("Num : " + str(T[i]))
    mod = T[i] % 2019
    # print("Mod : " + str(mod))
    if(mod in mod_dict.keys()):
        # mod_dict[mod] = mod_dict[mod] + 1
        count = count + 1
    else:
        mod_dict[mod] = 0
print(count)
#print(sum(mod_dict.values()))

Fixed submission:
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10
    x = x % 2019

for v in mods:
    count = count + v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)
count = 0
T = [0] * (n + 1)
mod_dict = {0:0}

for i in reversed(range(n)):
    #print(i)
    T[i] = T[i+1] + int(S[i]) * (10 ** (n - i - 1))
    # print("Num : " + str(T[i]))
    mod = T[i] % 2019
    # print("Mod : " + str(mod))
    if(mod in mod_dict.keys()):
        mod_dict[mod] = mod_dict[mod] + 1
    else:
        mod_dict[mod] = 0

print(sum(mod_dict.values()))

Fixed submission:
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10
    x = x % 2019

for v in mods:
    count = count + v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
length = len(S)
count = 0
for j in range(4, length+1, 1):
    for i in range(0,j-4, 1 ):
        subset = S[i:j]
        if(int(subset) % 2019 == 0):
            count = count + 1

print(count)

Fixed submission:
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10
    x = x % 2019

for v in mods:
    count = count + v*(v-1)//2

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
length = len(S)
count = 0
for j in range(1, length+1, 1):
    for i in range(0,j, 1 ):
        subset = S[i:j]
        if(int(subset) % 2019 == 0):
            count = count + 1

print(count)

Fixed submission:
reverse_S = input()[::-1]
n = len(reverse_S)
count = 0
mod = 0
mods = [0] * 2019
mods[0] = 1
x = 1
for s in reverse_S:
    mod = (mod + (int(s) * x)) % 2019
    mods[mod] = mods[mod] + 1
    x = x * 10
    x = x % 2019

for v in mods:
    count = count + v*(v-1)//2

print(count)